按钮显示在模拟器,但不是在真实设备 [英] Button shows in emulator but not in real device
问题描述
我想补充两个按钮
和一个的TextView
下的的ListView
动态。当我在模拟器中运行我的应用程序,这两个按钮
和文本
显示,但是他们不显示在真实的设备运行
。
I wanted to add two Buttons
and one textView
below the ListView
dynamically. When I run my app in the emulator, the two buttons
and text
are shown, however they are not showing when run in real device
.
在Android Studio中
在模拟器
在提交按钮
重叠相加索赔按钮
!
重叠的问题现在解决了,但按钮和文本仍然没有显示出更出现了一个ListView。
最新code如下:
under_list_view_button
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
>
<Button
android:layout_width="181dp"
android:layout_height="wrap_content"
android:id="@+id/addClaims1"
android:layout_marginLeft="15px"
android:drawableRight="@mipmap/claims"
android:text="Add Claims"/>
<Button
android:layout_width="130dp"
android:layout_height="wrap_content"
android:id="@+id/btnSave"
android:drawableRight="@mipmap/submit"
android:layout_marginLeft="450px"
android:text="Submit" />
</FrameLayout>
total_hours.xml
<?xml version="1.0" encoding="utf-8"?>
<AbsoluteLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<TextView
android:layout_width="175dp"
android:layout_height="33dp"
android:textColor="@color/indian_red"
android:textStyle="bold"
android:textSize="18sp"
android:id="@+id/textView10"
android:layout_x="174dp"
android:layout_y="16dp" />
</AbsoluteLayout>
正如我所说的两个按钮
和文本
如下在 ListView控件动态添加 ,所以他们不会显示如果没有的ListView
。
As I said the two button
and text
are added dynamically below the ListView, so they will not showing if no listView
.
活动A
footer = (AbsoluteLayout) getLayoutInflater().inflate(R.layout.total_hours, null);
totalHours = (TextView) footer.findViewById(R.id.textView10);
footerLayout = (FrameLayout) getLayoutInflater().inflate(R.layout.under_list_view_button, null);
btnSubmit = (Button) footerLayout.findViewById(R.id.btnSave);
btnAddClaims = (Button) footerLayout.findViewById(R.id.addClaims1);
objMyCustomBaseAdapter = new MyCustomBaseAdapter(getApplicationContext(), results, listview, footerLayout, footer);
listview.setAdapter(objMyCustomBaseAdapter);
@Override
public void onActivityResult(int requestCode, int resultCode, Intent data) { // receive from Activity B and populate ListView A
if (resultCode == RESULT_OK) {
if (requestCode == PROJECT_REQUEST_CODE) {
ReceiveProject = data.getStringExtra("Project");
ReceiveDescription = data.getStringExtra("Description");
ReceiveProgress = data.getIntExtra("progress", 0);
ReceiveTimeIn = data.getStringExtra("TimeIn");
ReceiveTimeOut = data.getStringExtra("TimeOut");
if (mClickedPosition == -1) { // if icon clicked
if (objMyCustomBaseAdapter != null)
objMyCustomBaseAdapter.addNewItem(ReceiveProject, ReceiveDescription, ReceiveProgress, ReceiveTimeIn, ReceiveTimeOut);
} else {
if (objMyCustomBaseAdapter != null)
objMyCustomBaseAdapter.changeItem(mClickedPosition, ReceiveProject, ReceiveDescription, ReceiveProgress, ReceiveTimeIn, ReceiveTimeOut);
}
MyCustomBaseAdapter
public class MyCustomBaseAdapter extends BaseAdapter{ // for ListView
private static ArrayList<SearchResults> searchArrayList;
FrameLayout footerLayout;
private LayoutInflater mInflater;
ListView listview;
AbsoluteLayout footer;
public MyCustomBaseAdapter(Context context, ArrayList<SearchResults> results,ListView listview,FrameLayout footerLayout,AbsoluteLayout footer) {
searchArrayList = results;
this.listview=listview;
this.footerLayout=footerLayout;
mInflater = LayoutInflater.from(context);
this.footer=footer;
addOrRemoveFooter();
}
public void addOrRemoveFooter(){
if(searchArrayList.size() == 0 && listview.getFooterViewsCount() > 0){
listview.removeFooterView(footer);
listview.removeFooterView(footerLayout);
}else if(listview.getFooterViewsCount() == 0 && searchArrayList.size() > 0){
listview.addFooterView(footer);
listview.addFooterView(footerLayout);
}
}
public void changeItem(int m,String P,String D,int Per,String TI,String TO)
{
SearchResults obj = new SearchResults();
obj.setProject(P);
obj.setDescription(" Work Description : " + D);
obj.setProgress(" Progress : " + Per);
obj.setTimeIn(" Time In : " + TI);
obj.setTimeOut(" Time Out : " + TO);
searchArrayList.set(m,obj);
this. notifyDataSetChanged();
}
public void addNewItem(String P,String D,int Per,String I,String O)
{
SearchResults obj = new SearchResults();
obj.setProject(P);
obj.setProgress(" Progress : " + Per);
obj.setTimeIn(" Time In : " + I);
obj.setTimeOut(" Time Out : " + O);
obj.setDescription(" Work Description : " + D);
searchArrayList.add(obj);
this. notifyDataSetChanged();
addOrRemoveFooter();
}
}
使用华为运行应用程序
我,它不会显示文本和按钮。但他们表现出的三星手机上运行时...
I using HuaWei to run the app, it does not shows text and buttons. But they show when running in Samsung phone...
推荐答案
使用此code:
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent" >
<RelativeLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:gravity="center" >
<Button
android:id="@+id/addClaims1"
android:layout_width="181dp"
android:layout_height="wrap_content"
android:layout_marginLeft="15px"
android:text="Add Claims" />
<Button
android:id="@+id/btnSave"
android:layout_width="130dp"
android:layout_height="wrap_content"
android:layout_marginLeft="5px"
android:layout_toRightOf="@+id/addClaims1"
android:text="Submit" />
</RelativeLayout>
</FrameLayout>
这篇关于按钮显示在模拟器,但不是在真实设备的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!