2015-12-09 11 views
0

Я хотел добавить два Buttons и один textView под ListView динамически. Когда я запускаю свое приложение в эмуляторе, отображаются два buttons и text, однако они не показывают при запуске в real device.Кнопки отображаются в эмуляторе, но не в реальном устройстве

В андроиде студии

enter image description here

В эмуляторе

enter image description here

Передать Button перекрытия добавить претензии Button!

Проблема перекрытия решена сейчас, но кнопки и текст все еще не отображаются, даже там есть listView.

Последний код, как показано ниже:

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> 

Как я сказал, что два button и text добавляются динамически ниже ListView, поэтому они не будут отображаться, если нет listView.

активность

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(); 

    } 
} 

Я с помощью HUAWEI, чтобы запустить приложение, оно не показывает текст и кнопки. Но они показывают при работе в Samsung телефон ...

+0

Оставьте свой код. – Jas

+0

@Jas posted .... – Tony

+0

Ваш java-код i mean – Jas

ответ

0

Используйте этот код:

<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> 
+0

Спасибо, теперь он не перекрывается, но кнопка все еще не отображается – Tony

+0

ok я обновлю ответ, проверьте его –

+0

не повезло ....: .. ( – Tony

1

Если вы хотите, чтобы не пересекаться кнопки:

  1. Дайте btnSave на право из addClaims1
  2. Уменьшение marginLeft к чему-то около 15px (как кнопка addClaims1)
+0

кнопка все еще не отображается ... – Tony

+0

Не могли бы вы внести ваши изменения? – virusivv

+0

Подождите минуту .. – Tony

Смежные вопросы