2016-12-13 2 views
-1

Je veux montrer des données de string.xml de string-array dans ce genre de tableaucomment afficher les données dans la liste-vue (recyclerview est mieux)?

ci-dessous est l'image de la table Je cherche:

enter image description here

Je dois faire custom adapter mais je ne savent comment

est Ci-dessous le code pour mon habitude listview

<?xml version="1.0" encoding="utf-8"?> 
<RelativeLayout 
xmlns:android="http://schemas.android.com/apk/res/android" 
android:layout_width="match_parent" 
android:layout_height="match_parent" 
xmlns:tools="http://schemas.android.com/tools"> 

<TextView 
    android:id="@+id/list_item_string" 
    tools:text="asifgiouweifhsklajfhkh" 
    android:layout_width="wrap_content" 
    android:layout_height="match_parent" 
    android:layout_centerVertical="true" 
    android:layout_alignParentLeft="true" 
    android:gravity="center" 
    android:paddingLeft="8dp" 
    android:textSize="18sp" 
    android:textStyle="bold" 
    android:layout_toStartOf="@+id/quantityView"/> 

<Button 
    android:id="@+id/delete_btn" 
    android:layout_width="wrap_content" 
    android:layout_height="match_parent" 
    android:gravity="center" 
    android:layout_alignParentRight="true" 
    android:layout_centerVertical="true" 
    android:layout_marginRight="5dp" 
    android:text="??" /> 

<TextView 
    android:text="QO" 
    android:gravity="center" 
    android:layout_width="wrap_content" 
    android:layout_height="match_parent" 
    android:layout_alignBottom="@+id/list_item_string" 
    android:layout_alignEnd="@+id/delete_btn" 
    android:layout_marginEnd="80dp" 
    android:id="@+id/unitView"/> 

<TextView 
    android:text="1234" 
    android:layout_width="wrap_content" 
    android:layout_height="match_parent" 
    android:id="@+id/quantityView" 
    android:layout_alignBottom="@+id/unitView" 
    android:layout_toStartOf="@+id/unitView" 
    android:layout_alignParentTop="true"/> 

Comment faire? Merci

+0

vous pouvez utiliser listview et recyclerview pour cela. Il suffit de créer une mise en page pour chaque ligne. –

+0

le code xml ci-dessus est la mise en page pour chaque ligne. il a plusieurs colonnes. J'ai fait quelques recherches que je dois faire un adapteur fait sur commande mais je ne sais pas comment faire cela. –

+0

Je poste le code adaptateur personnalisé –

Répondre

0

Adaptateur pour Listview:

public class TalktimeAdapter extends ArrayAdapter<PlanDetails> { 


    Context context; 
    View view; 


    public TalktimeAdapter(Context context,List<PlanDetails> items) { 
     super(context,0, items); 
     this.context=context; 
    } 

    @Override 
    public View getView(int position, View convertView, ViewGroup parent) { 

     PlanDetails rowitem= getItem(position); 
     view=convertView; 
     ViewHolder holder; 

     if (view==null){ 
      LayoutInflater inflater=(LayoutInflater)context.getSystemService(Context.LAYOUT_INFLATER_SERVICE); 
      view=inflater.inflate(R.layout.fulltalk_items,parent,false); 
      holder=new ViewHolder(); 

      holder.planoverview=(TextView)view.findViewById(R.id.planoverview); 
      holder.planbenefit=(TextView)view.findViewById(R.id.planbenefit); 
      holder.planamount=(TextView)view.findViewById(R.id.planamount); 
      view.setTag(holder); 

     }else{ 
      holder=(ViewHolder)view.getTag(); 
     } 

     assert rowitem != null; 
     holder.planoverview.setText(rowitem.getOne()); 
     holder.planbenefit.setText(rowitem.getTwo()); 
     holder.planamount.setText(rowitem.getThree()); 


     return view; 

    } 
    private static class ViewHolder 
    { 
     TextView planoverview,planbenefit,planamount; 
    } 
} 

classe Model:

public class PlanDetails { 

    String one,two,three; 


    public PlanDetails(String one, String two, String three) { 
     this.one = one; 
     this.two = two; 
     this.three = three; 
    } 


    public String getThree() { 
     return three; 
    } 

    public void setThree(String three) { 
     this.three = three; 
    } 

    public String getTwo() { 
     return two; 
    } 

    public void setTwo(String two) { 
     this.two = two; 
    } 

    public String getOne() { 
     return one; 
    } 

    public void setOne(String one) { 
     this.one = one; 
    } 
} 

Activité:

public class FullTalkTimeActivity extends AppCompatActivity { 

    ListView listView; 
    TalktimeAdapter adapter; 
    List<PlanDetails> row; 

     @Override 
    protected void onCreate(@Nullable Bundle savedInstanceState) { 
     super.onCreate(savedInstanceState); 
     setContentView(R.layout.fulltalk_view); 

     listView=(ListView)findViewById(R.id.planList); 

     row = new ArrayList<>(); 
     row.add(new PlanDetails("oneoneone","twotwotwo","11")); 
     row.add(new PlanDetails("oneoneone","twotwotwo","12")); 
     row.add(new PlanDetails("oneoneone","twotwotwo","13")); 
     row.add(new PlanDetails("oneoneone","twotwotwo","14")); 
     row.add(new PlanDetails("oneoneone","twotwotwo","15")); 
     row.add(new PlanDetails("oneoneone","twotwotwo","16")); 
     row.add(new PlanDetails("oneoneone","twotwotwo","17")); 
     row.add(new PlanDetails("oneoneone","twotwotwo","18")); 
     row.add(new PlanDetails("oneoneone","twotwotwo","19")); 
     row.add(new PlanDetails("oneoneone","twotwotwo","21")); 
     row.add(new PlanDetails("oneoneone","twotwotwo","31")); 
     row.add(new PlanDetails("oneoneone","twotwotwo","41")); 
     row.add(new PlanDetails("oneoneone","twotwotwo","51")); 
     row.add(new PlanDetails("oneoneone","twotwotwo","61")); 
     row.add(new PlanDetails("oneoneone","twotwotwo","71")); 
     row.add(new PlanDetails("oneoneone","twotwotwo","81")); 
     row.add(new PlanDetails("oneoneone","twotwotwo","91")); 
     row.add(new PlanDetails("oneoneone","twotwotwo","101")); 
     row.add(new PlanDetails("oneoneone","twotwotwo","121")); 
     row.add(new PlanDetails("oneoneone","twotwotwo","1011")); 
     row.add(new PlanDetails("oneoneone","twotwotwo","1521")); 
     row.add(new PlanDetails("oneoneone","twotwotwo","1081")); 
     row.add(new PlanDetails("oneoneone","twotwotwo","1291")); 
     row.add(new PlanDetails("oneoneone","twotwotwo","1001")); 
     row.add(new PlanDetails("oneoneone","twotwotwo","1261")); 


     listView.setOnItemClickListener(new AdapterView.OnItemClickListener() { 
      @Override 
      public void onItemClick(AdapterView<?> adapterView, View view, int i, long l) { 
       PlanDetails pm= row.get(i); 
        Toast.makeText(FullTalkTimeActivity.this,pm.getThree().trim(),Toast.LENGTH_SHORT).show(); 


      } 
     }); 
     adapter = new TalktimeAdapter(getActivity(), row); 
     listView.setAdapter(adapter); 
     adapter.notifyDataSetChanged(); 

     } 

} 
+0

comment démarrer une conversation? –

+0

écrire des commentaires et des options de discussion –