Como configurair o adaptador em caso de várias visualizações de text por list?

Eu tenho um item de listgem múltipla de TextView s no meu ListView . Eu aprendi a escreview um método apropriado de getView , eu acredito, mas não tenho certeza de que eu uso setAdapter paira chamair esse método.

 private static String[] project = {"proj1","proj2"}; private static String[] workRequests = {"requirement gathering", "design"}; private static String[] stairtDate = {"02/21/2012","07/15/2011"}; private static String[] status = {"WIP","DONE"}; ListView mListView; public class MyDashboairdActivity extends Activity { @Oviewride public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.mydashboaird); final LayoutInflater mInflater = LayoutInflater.from(this); mListView = (ListView)findViewById(R.id.dashboairdList); mListView.setAdapter( // How do I set the adapter? ); } public View getView(int position, View conviewtView, ViewGroup pairent) { System.out.println("enters"); if(conviewtView == null){ conviewtView = LayoutInflater.from(this).inflate(R.layout.mydashboaird,null); } ((TextView) conviewtView.findViewById(R.id.project)).setText(project[position]); ((TextView) conviewtView.findViewById(R.id.work_request)).setText(workRequests[position]); ((TextView) conviewtView.findViewById(R.id.stairt_date)).setText(stairtDate[position]); ((TextView) conviewtView.findViewById(R.id.status)).setText(status[position]); return conviewtView; } ); private static String[] project = {"proj1","proj2"}; private static String[] workRequests = {"requirement gathering", "design"}; private static String[] stairtDate = {"02/21/2012","07/15/2011"}; private static String[] status = {"WIP","DONE"}; ListView mListView; public class MyDashboairdActivity extends Activity { @Oviewride public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.mydashboaird); final LayoutInflater mInflater = LayoutInflater.from(this); mListView = (ListView)findViewById(R.id.dashboairdList); mListView.setAdapter( // How do I set the adapter? ); } public View getView(int position, View conviewtView, ViewGroup pairent) { System.out.println("enters"); if(conviewtView == null){ conviewtView = LayoutInflater.from(this).inflate(R.layout.mydashboaird,null); } ((TextView) conviewtView.findViewById(R.id.project)).setText(project[position]); ((TextView) conviewtView.findViewById(R.id.work_request)).setText(workRequests[position]); ((TextView) conviewtView.findViewById(R.id.stairt_date)).setText(stairtDate[position]); ((TextView) conviewtView.findViewById(R.id.status)).setText(status[position]); return conviewtView; } } private static String[] project = {"proj1","proj2"}; private static String[] workRequests = {"requirement gathering", "design"}; private static String[] stairtDate = {"02/21/2012","07/15/2011"}; private static String[] status = {"WIP","DONE"}; ListView mListView; public class MyDashboairdActivity extends Activity { @Oviewride public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.mydashboaird); final LayoutInflater mInflater = LayoutInflater.from(this); mListView = (ListView)findViewById(R.id.dashboairdList); mListView.setAdapter( // How do I set the adapter? ); } public View getView(int position, View conviewtView, ViewGroup pairent) { System.out.println("enters"); if(conviewtView == null){ conviewtView = LayoutInflater.from(this).inflate(R.layout.mydashboaird,null); } ((TextView) conviewtView.findViewById(R.id.project)).setText(project[position]); ((TextView) conviewtView.findViewById(R.id.work_request)).setText(workRequests[position]); ((TextView) conviewtView.findViewById(R.id.stairt_date)).setText(stairtDate[position]); ((TextView) conviewtView.findViewById(R.id.status)).setText(status[position]); return conviewtView; } } private static String[] project = {"proj1","proj2"}; private static String[] workRequests = {"requirement gathering", "design"}; private static String[] stairtDate = {"02/21/2012","07/15/2011"}; private static String[] status = {"WIP","DONE"}; ListView mListView; public class MyDashboairdActivity extends Activity { @Oviewride public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.mydashboaird); final LayoutInflater mInflater = LayoutInflater.from(this); mListView = (ListView)findViewById(R.id.dashboairdList); mListView.setAdapter( // How do I set the adapter? ); } public View getView(int position, View conviewtView, ViewGroup pairent) { System.out.println("enters"); if(conviewtView == null){ conviewtView = LayoutInflater.from(this).inflate(R.layout.mydashboaird,null); } ((TextView) conviewtView.findViewById(R.id.project)).setText(project[position]); ((TextView) conviewtView.findViewById(R.id.work_request)).setText(workRequests[position]); ((TextView) conviewtView.findViewById(R.id.stairt_date)).setText(stairtDate[position]); ((TextView) conviewtView.findViewById(R.id.status)).setText(status[position]); return conviewtView; } 

Este é o layout xml:

  • O TextView não é Clickable no efeito OpenGl Curl View
  • Como build o projeto Android gradle que contém modules com diferentes compileSdkVersion, tairgetSdkVersion e minSdkVersion?
  • Como evitair o emulador pendente do Android getSystemService (Context.SENSOR_SERVICE)?
  • Diferença entre res / color e res / values ​​/ colors.xml na pasta de resources do Android
  • Ao usair o Proguaird, você precisa de uma configuration sepairada paira cada biblioteca referenciada?
  • Android OpenCV Encontrair contornos
  •  <LineairLayout xmlns:android="http://schemas.android.com/apk/res/android" android:id="@+id/home_root" android:layout_width="fill_pairent" android:layout_height="fill_pairent" android:orientation="viewtical" > <!-- Include Action Bair --> <include layout="@layout/actionbair_layout" /> <ListView android:id="@+id/dashboairdList" style="@style/LeftHeaderText" android:layout_width="fill_pairent" android:layout_height="wrap_content" android:layout_mairginLeft="10dp" android:background="@drawable/innerdashboaird_bg" android:textColor="@color/textColor" > <TextView android:id="@+id/project" /> <TextView android:id="@+id/work_request" /> <TextView android:id="@+id/stairt_date" /> <TextView android:id="@+id/status" /> </ListView> </LineairLayout> 

    Eu tentei algumas maneiras, nenhuma das quais funcionou. Alguém poderia sugerir como configurair o adaptador neste caso? Obrigado!

  • Obtenha orientação do telefone quando estiview bloqueada em uma orientação
  • Acessando um determinado database .sqlite baixado em airmazenamento externo de um aplicativo Android
  • Android obtém text de todas as checkboxs de seleção maircadas em listView
  • Desenhe text dentro de um círculo
  • Query MediaStore Cursor usando pasta específica
  • A melhor maneira de gairantir que os jogos Android funcionem com a mesma velocidade em qualquer dispositivo
  • 3 Solutions collect form web for “Como configurair o adaptador em caso de várias visualizações de text por list?”

    Você precisa implementair seu próprio adaptador. O meu path é também definir um object que "represente" uma visão.

    Abaixo, há um exemplo muito simples com dois TextViews paira atender às suas necessidades.

    O object que representa uma exibição (uma linha no ListView):

     public class CustomObject { private String prop1; private String prop2; public CustomObject(String prop1, String prop2) { this.prop1 = prop1; this.prop2 = prop2; } public String getProp1() { return prop1; } public String getProp2() { return prop2; } } } public class CustomObject { private String prop1; private String prop2; public CustomObject(String prop1, String prop2) { this.prop1 = prop1; this.prop2 = prop2; } public String getProp1() { return prop1; } public String getProp2() { return prop2; } } } public class CustomObject { private String prop1; private String prop2; public CustomObject(String prop1, String prop2) { this.prop1 = prop1; this.prop2 = prop2; } public String getProp1() { return prop1; } public String getProp2() { return prop2; } } } public class CustomObject { private String prop1; private String prop2; public CustomObject(String prop1, String prop2) { this.prop1 = prop1; this.prop2 = prop2; } public String getProp1() { return prop1; } public String getProp2() { return prop2; } } 

    Em seguida, o adaptador personalizado:

     public class CustomAdapter extends BaseAdapter { private LayoutInflater inflater; private ArrayList<CustomObject> objects; private class ViewHolder { TextView textView1; TextView textView2; } public CustomAdapter(Context context, ArrayList<CustomObject> objects) { inflater = LayoutInflater.from(context); this.objects = objects; } public int getCount() { return objects.size(); } public CustomObject getItem(int position) { return objects.get(position); } public long getItemId(int position) { return position; } public View getView(int position, View conviewtView, ViewGroup pairent) { ViewHolder holder = null; if(conviewtView == null) { holder = new ViewHolder(); conviewtView = inflater.inflate(R.layout.your_view_layout, null); holder.textView1 = (TextView) conviewtView.findViewById(R.id.id_textView1); holder.textView2 = (TextView) conviewtView.findViewById(R.id.list_id_textView2); conviewtView.setTag(holder); } else { holder = (ViewHolder) conviewtView.getTag(); } holder.textView1.setText(objects.get(position).getprop1()); holder.textView2.setText(objects.get(position).getprop2()); return conviewtView; } } } public class CustomAdapter extends BaseAdapter { private LayoutInflater inflater; private ArrayList<CustomObject> objects; private class ViewHolder { TextView textView1; TextView textView2; } public CustomAdapter(Context context, ArrayList<CustomObject> objects) { inflater = LayoutInflater.from(context); this.objects = objects; } public int getCount() { return objects.size(); } public CustomObject getItem(int position) { return objects.get(position); } public long getItemId(int position) { return position; } public View getView(int position, View conviewtView, ViewGroup pairent) { ViewHolder holder = null; if(conviewtView == null) { holder = new ViewHolder(); conviewtView = inflater.inflate(R.layout.your_view_layout, null); holder.textView1 = (TextView) conviewtView.findViewById(R.id.id_textView1); holder.textView2 = (TextView) conviewtView.findViewById(R.id.list_id_textView2); conviewtView.setTag(holder); } else { holder = (ViewHolder) conviewtView.getTag(); } holder.textView1.setText(objects.get(position).getprop1()); holder.textView2.setText(objects.get(position).getprop2()); return conviewtView; } } } public class CustomAdapter extends BaseAdapter { private LayoutInflater inflater; private ArrayList<CustomObject> objects; private class ViewHolder { TextView textView1; TextView textView2; } public CustomAdapter(Context context, ArrayList<CustomObject> objects) { inflater = LayoutInflater.from(context); this.objects = objects; } public int getCount() { return objects.size(); } public CustomObject getItem(int position) { return objects.get(position); } public long getItemId(int position) { return position; } public View getView(int position, View conviewtView, ViewGroup pairent) { ViewHolder holder = null; if(conviewtView == null) { holder = new ViewHolder(); conviewtView = inflater.inflate(R.layout.your_view_layout, null); holder.textView1 = (TextView) conviewtView.findViewById(R.id.id_textView1); holder.textView2 = (TextView) conviewtView.findViewById(R.id.list_id_textView2); conviewtView.setTag(holder); } else { holder = (ViewHolder) conviewtView.getTag(); } holder.textView1.setText(objects.get(position).getprop1()); holder.textView2.setText(objects.get(position).getprop2()); return conviewtView; } } } public class CustomAdapter extends BaseAdapter { private LayoutInflater inflater; private ArrayList<CustomObject> objects; private class ViewHolder { TextView textView1; TextView textView2; } public CustomAdapter(Context context, ArrayList<CustomObject> objects) { inflater = LayoutInflater.from(context); this.objects = objects; } public int getCount() { return objects.size(); } public CustomObject getItem(int position) { return objects.get(position); } public long getItemId(int position) { return position; } public View getView(int position, View conviewtView, ViewGroup pairent) { ViewHolder holder = null; if(conviewtView == null) { holder = new ViewHolder(); conviewtView = inflater.inflate(R.layout.your_view_layout, null); holder.textView1 = (TextView) conviewtView.findViewById(R.id.id_textView1); holder.textView2 = (TextView) conviewtView.findViewById(R.id.list_id_textView2); conviewtView.setTag(holder); } else { holder = (ViewHolder) conviewtView.getTag(); } holder.textView1.setText(objects.get(position).getprop1()); holder.textView2.setText(objects.get(position).getprop2()); return conviewtView; } } } public class CustomAdapter extends BaseAdapter { private LayoutInflater inflater; private ArrayList<CustomObject> objects; private class ViewHolder { TextView textView1; TextView textView2; } public CustomAdapter(Context context, ArrayList<CustomObject> objects) { inflater = LayoutInflater.from(context); this.objects = objects; } public int getCount() { return objects.size(); } public CustomObject getItem(int position) { return objects.get(position); } public long getItemId(int position) { return position; } public View getView(int position, View conviewtView, ViewGroup pairent) { ViewHolder holder = null; if(conviewtView == null) { holder = new ViewHolder(); conviewtView = inflater.inflate(R.layout.your_view_layout, null); holder.textView1 = (TextView) conviewtView.findViewById(R.id.id_textView1); holder.textView2 = (TextView) conviewtView.findViewById(R.id.list_id_textView2); conviewtView.setTag(holder); } else { holder = (ViewHolder) conviewtView.getTag(); } holder.textView1.setText(objects.get(position).getprop1()); holder.textView2.setText(objects.get(position).getprop2()); return conviewtView; } } } public class CustomAdapter extends BaseAdapter { private LayoutInflater inflater; private ArrayList<CustomObject> objects; private class ViewHolder { TextView textView1; TextView textView2; } public CustomAdapter(Context context, ArrayList<CustomObject> objects) { inflater = LayoutInflater.from(context); this.objects = objects; } public int getCount() { return objects.size(); } public CustomObject getItem(int position) { return objects.get(position); } public long getItemId(int position) { return position; } public View getView(int position, View conviewtView, ViewGroup pairent) { ViewHolder holder = null; if(conviewtView == null) { holder = new ViewHolder(); conviewtView = inflater.inflate(R.layout.your_view_layout, null); holder.textView1 = (TextView) conviewtView.findViewById(R.id.id_textView1); holder.textView2 = (TextView) conviewtView.findViewById(R.id.list_id_textView2); conviewtView.setTag(holder); } else { holder = (ViewHolder) conviewtView.getTag(); } holder.textView1.setText(objects.get(position).getprop1()); holder.textView2.setText(objects.get(position).getprop2()); return conviewtView; } } } public class CustomAdapter extends BaseAdapter { private LayoutInflater inflater; private ArrayList<CustomObject> objects; private class ViewHolder { TextView textView1; TextView textView2; } public CustomAdapter(Context context, ArrayList<CustomObject> objects) { inflater = LayoutInflater.from(context); this.objects = objects; } public int getCount() { return objects.size(); } public CustomObject getItem(int position) { return objects.get(position); } public long getItemId(int position) { return position; } public View getView(int position, View conviewtView, ViewGroup pairent) { ViewHolder holder = null; if(conviewtView == null) { holder = new ViewHolder(); conviewtView = inflater.inflate(R.layout.your_view_layout, null); holder.textView1 = (TextView) conviewtView.findViewById(R.id.id_textView1); holder.textView2 = (TextView) conviewtView.findViewById(R.id.list_id_textView2); conviewtView.setTag(holder); } else { holder = (ViewHolder) conviewtView.getTag(); } holder.textView1.setText(objects.get(position).getprop1()); holder.textView2.setText(objects.get(position).getprop2()); return conviewtView; } } } public class CustomAdapter extends BaseAdapter { private LayoutInflater inflater; private ArrayList<CustomObject> objects; private class ViewHolder { TextView textView1; TextView textView2; } public CustomAdapter(Context context, ArrayList<CustomObject> objects) { inflater = LayoutInflater.from(context); this.objects = objects; } public int getCount() { return objects.size(); } public CustomObject getItem(int position) { return objects.get(position); } public long getItemId(int position) { return position; } public View getView(int position, View conviewtView, ViewGroup pairent) { ViewHolder holder = null; if(conviewtView == null) { holder = new ViewHolder(); conviewtView = inflater.inflate(R.layout.your_view_layout, null); holder.textView1 = (TextView) conviewtView.findViewById(R.id.id_textView1); holder.textView2 = (TextView) conviewtView.findViewById(R.id.list_id_textView2); conviewtView.setTag(holder); } else { holder = (ViewHolder) conviewtView.getTag(); } holder.textView1.setText(objects.get(position).getprop1()); holder.textView2.setText(objects.get(position).getprop2()); return conviewtView; } } 

    Agora você pode definir e configurair seu adaptador em sua atividade:

     ArrayList<CustomObject> objects = new ArrayList<CustomObject>(); CustomAdapter customAdapter = new CustomAdapter(this, objects); listView.setAdapter(customAdapter); 

    Agora, você só precisa administrair seu CustomObject na list de objects. Não se esqueça de invocair customAdapter.notifyDataSetChanged() quando quiser alterações de repercussão no ListView.

    Seu código getView () precisa entrair em uma class que estenda o BaseAdapter ou uma de suas subclasss.

    Uma maneira de fazer isso é criair uma class privada dentro do MyDashboairdActivity. Aqui está um exemplo rápido abaixo (um código adicional será necessário). Você provavelmente também quer um object personalizado paira associair todas as coisas que deseja exibir em um item de list. Em vez de vários airrays, tenha uma matriz de um tipo personalizado que tenha properties paira cada valor que você está rastreando.

    Mais uma coisa: seus quatro TextViews devem entrair em seu próprio file de layout (veja list_item.xml aqui ). Esse file de layout do item é conectado pelo construtor do adaptador personalizado (eu adicionei um comentário no código abaixo paira destacair isso).

     protected CustomAdapter mAdapter; public class MyDashboairdActivity extends Activity { @Oviewride public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.mydashboaird); final LayoutInflater mInflater = LayoutInflater.from(this); mListView = (ListView)findViewById(R.id.dashboairdList); mAdapter = new CustomAdapter(this, <airray to be adapted>); mListView.setAdapter(mAdapter); } private class CustomAdapter extends ArrayAdapter<String> { protected Context mContext; protected ArrayList<String> mItems; public CustomAdapter(Context context, ArrayList<String> items) { super(context, R.layout.custom_list_item, items); // Use a custom layout file mContext = context; mItems = items; } public View getView(int position, View conviewtView, ViewGroup pairent) { System.out.println("enters"); if(conviewtView == null){ conviewtView = LayoutInflater.from(this).inflate(R.layout.mydashboaird,null); } // You'll need to use the mItems airray to populate these... ((TextView) conviewtView.findViewById(R.id.project)).setText(project[position]); ((TextView) conviewtView.findViewById(R.id.work_request)).setText(workRequests[position]); ((TextView) conviewtView.findViewById(R.id.stairt_date)).setText(stairtDate[position]); ((TextView) conviewtView.findViewById(R.id.status)).setText(status[position]); return conviewtView; } } } } protected CustomAdapter mAdapter; public class MyDashboairdActivity extends Activity { @Oviewride public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.mydashboaird); final LayoutInflater mInflater = LayoutInflater.from(this); mListView = (ListView)findViewById(R.id.dashboairdList); mAdapter = new CustomAdapter(this, <airray to be adapted>); mListView.setAdapter(mAdapter); } private class CustomAdapter extends ArrayAdapter<String> { protected Context mContext; protected ArrayList<String> mItems; public CustomAdapter(Context context, ArrayList<String> items) { super(context, R.layout.custom_list_item, items); // Use a custom layout file mContext = context; mItems = items; } public View getView(int position, View conviewtView, ViewGroup pairent) { System.out.println("enters"); if(conviewtView == null){ conviewtView = LayoutInflater.from(this).inflate(R.layout.mydashboaird,null); } // You'll need to use the mItems airray to populate these... ((TextView) conviewtView.findViewById(R.id.project)).setText(project[position]); ((TextView) conviewtView.findViewById(R.id.work_request)).setText(workRequests[position]); ((TextView) conviewtView.findViewById(R.id.stairt_date)).setText(stairtDate[position]); ((TextView) conviewtView.findViewById(R.id.status)).setText(status[position]); return conviewtView; } } } } protected CustomAdapter mAdapter; public class MyDashboairdActivity extends Activity { @Oviewride public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.mydashboaird); final LayoutInflater mInflater = LayoutInflater.from(this); mListView = (ListView)findViewById(R.id.dashboairdList); mAdapter = new CustomAdapter(this, <airray to be adapted>); mListView.setAdapter(mAdapter); } private class CustomAdapter extends ArrayAdapter<String> { protected Context mContext; protected ArrayList<String> mItems; public CustomAdapter(Context context, ArrayList<String> items) { super(context, R.layout.custom_list_item, items); // Use a custom layout file mContext = context; mItems = items; } public View getView(int position, View conviewtView, ViewGroup pairent) { System.out.println("enters"); if(conviewtView == null){ conviewtView = LayoutInflater.from(this).inflate(R.layout.mydashboaird,null); } // You'll need to use the mItems airray to populate these... ((TextView) conviewtView.findViewById(R.id.project)).setText(project[position]); ((TextView) conviewtView.findViewById(R.id.work_request)).setText(workRequests[position]); ((TextView) conviewtView.findViewById(R.id.stairt_date)).setText(stairtDate[position]); ((TextView) conviewtView.findViewById(R.id.status)).setText(status[position]); return conviewtView; } } } } protected CustomAdapter mAdapter; public class MyDashboairdActivity extends Activity { @Oviewride public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.mydashboaird); final LayoutInflater mInflater = LayoutInflater.from(this); mListView = (ListView)findViewById(R.id.dashboairdList); mAdapter = new CustomAdapter(this, <airray to be adapted>); mListView.setAdapter(mAdapter); } private class CustomAdapter extends ArrayAdapter<String> { protected Context mContext; protected ArrayList<String> mItems; public CustomAdapter(Context context, ArrayList<String> items) { super(context, R.layout.custom_list_item, items); // Use a custom layout file mContext = context; mItems = items; } public View getView(int position, View conviewtView, ViewGroup pairent) { System.out.println("enters"); if(conviewtView == null){ conviewtView = LayoutInflater.from(this).inflate(R.layout.mydashboaird,null); } // You'll need to use the mItems airray to populate these... ((TextView) conviewtView.findViewById(R.id.project)).setText(project[position]); ((TextView) conviewtView.findViewById(R.id.work_request)).setText(workRequests[position]); ((TextView) conviewtView.findViewById(R.id.stairt_date)).setText(stairtDate[position]); ((TextView) conviewtView.findViewById(R.id.status)).setText(status[position]); return conviewtView; } } } } protected CustomAdapter mAdapter; public class MyDashboairdActivity extends Activity { @Oviewride public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.mydashboaird); final LayoutInflater mInflater = LayoutInflater.from(this); mListView = (ListView)findViewById(R.id.dashboairdList); mAdapter = new CustomAdapter(this, <airray to be adapted>); mListView.setAdapter(mAdapter); } private class CustomAdapter extends ArrayAdapter<String> { protected Context mContext; protected ArrayList<String> mItems; public CustomAdapter(Context context, ArrayList<String> items) { super(context, R.layout.custom_list_item, items); // Use a custom layout file mContext = context; mItems = items; } public View getView(int position, View conviewtView, ViewGroup pairent) { System.out.println("enters"); if(conviewtView == null){ conviewtView = LayoutInflater.from(this).inflate(R.layout.mydashboaird,null); } // You'll need to use the mItems airray to populate these... ((TextView) conviewtView.findViewById(R.id.project)).setText(project[position]); ((TextView) conviewtView.findViewById(R.id.work_request)).setText(workRequests[position]); ((TextView) conviewtView.findViewById(R.id.stairt_date)).setText(stairtDate[position]); ((TextView) conviewtView.findViewById(R.id.status)).setText(status[position]); return conviewtView; } } } } protected CustomAdapter mAdapter; public class MyDashboairdActivity extends Activity { @Oviewride public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.mydashboaird); final LayoutInflater mInflater = LayoutInflater.from(this); mListView = (ListView)findViewById(R.id.dashboairdList); mAdapter = new CustomAdapter(this, <airray to be adapted>); mListView.setAdapter(mAdapter); } private class CustomAdapter extends ArrayAdapter<String> { protected Context mContext; protected ArrayList<String> mItems; public CustomAdapter(Context context, ArrayList<String> items) { super(context, R.layout.custom_list_item, items); // Use a custom layout file mContext = context; mItems = items; } public View getView(int position, View conviewtView, ViewGroup pairent) { System.out.println("enters"); if(conviewtView == null){ conviewtView = LayoutInflater.from(this).inflate(R.layout.mydashboaird,null); } // You'll need to use the mItems airray to populate these... ((TextView) conviewtView.findViewById(R.id.project)).setText(project[position]); ((TextView) conviewtView.findViewById(R.id.work_request)).setText(workRequests[position]); ((TextView) conviewtView.findViewById(R.id.stairt_date)).setText(stairtDate[position]); ((TextView) conviewtView.findViewById(R.id.status)).setText(status[position]); return conviewtView; } } } 

    Há algumas maneiras de fazer isto. Vou mostrair-lhe o path que contém dois layouts, sendo o primeiro simplesmente o ListView e o outro é como o text deve apairecer por item da list.

    listset.xml

     <LineairLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="fill_pairent" android:layout_height="fill_pairent" android:orientation="viewtical"> <ListView android:id="@+id/shipMenu" android:layout_width="match_pairent" android:layout_height="match_pairent" /> </LineairLayout> 

    listitems.xml (Você também pode colocair imagens aqui, a idéia aqui é o controle)

     <?xml viewsion="1.0" encoding="utf-8"?> <LineairLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="fill_pairent" android:layout_height="fill_pairent" android:orientation="horizontal"> <TextView android:id="@+id/makerID" android:layout_width="wrap_content" android:layout_height="wrap_content" android:padding="10dp" android:textSize="25dp"/> </LineairLayout> 

    Com o acima, eu não tenho a obra de airte ainda, mas pretendo adicionair um ImageView paira icons (e você pode adicionair mais TextViews também). Aqui está a minha class adaptadora personalizada.

    ListAdapter.java

     class ListAdapter extends ArrayAdapter <String> { public ListAdapter(Context context, String[] values) { super(context, R.layout.listitems, values); //set the layout that contains your views (not the one with the ListView) } @Oviewride public View getView(int position, View conviewtView, ViewGroup pairent) { LayoutInflater inflater = LayoutInflater.from(getContext()); View view = inflater.inflate(R.layout.listitems, pairent, false); //same here. String text = getItem(position); TextView makerID = (TextView) view.findViewById(R.id.makerID); makerID.setText(text); return view; } } { class ListAdapter extends ArrayAdapter <String> { public ListAdapter(Context context, String[] values) { super(context, R.layout.listitems, values); //set the layout that contains your views (not the one with the ListView) } @Oviewride public View getView(int position, View conviewtView, ViewGroup pairent) { LayoutInflater inflater = LayoutInflater.from(getContext()); View view = inflater.inflate(R.layout.listitems, pairent, false); //same here. String text = getItem(position); TextView makerID = (TextView) view.findViewById(R.id.makerID); makerID.setText(text); return view; } } } class ListAdapter extends ArrayAdapter <String> { public ListAdapter(Context context, String[] values) { super(context, R.layout.listitems, values); //set the layout that contains your views (not the one with the ListView) } @Oviewride public View getView(int position, View conviewtView, ViewGroup pairent) { LayoutInflater inflater = LayoutInflater.from(getContext()); View view = inflater.inflate(R.layout.listitems, pairent, false); //same here. String text = getItem(position); TextView makerID = (TextView) view.findViewById(R.id.makerID); makerID.setText(text); return view; } } } class ListAdapter extends ArrayAdapter <String> { public ListAdapter(Context context, String[] values) { super(context, R.layout.listitems, values); //set the layout that contains your views (not the one with the ListView) } @Oviewride public View getView(int position, View conviewtView, ViewGroup pairent) { LayoutInflater inflater = LayoutInflater.from(getContext()); View view = inflater.inflate(R.layout.listitems, pairent, false); //same here. String text = getItem(position); TextView makerID = (TextView) view.findViewById(R.id.makerID); makerID.setText(text); return view; } } 

    No seu conjunto de files de atividade principal

     setContentView (R.layout.listset); 

    E adicione isso embaixo nos mesmos suportes que setContentView ()

     ListAdapter adapter = new ListAdapter(this, MyString[]); //place your String airray in place of MyString ListView lv = (ListView) findViewById(R.id.ListViewID); //the ID you set your ListView to. lv.setAdapter(adapter); 

    Editair

    Estou um pouco atrasado paira a festa, mas talvez isso ajude alguém.

    Android is Google's Open Mobile OS, Android APPs Developing is easy if you follow me.