Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Well my code is a mess. Check the tutorial here is <a href="http://www.vogella.com/articles/AndroidListView/article.html#tutorial_ownadapter" rel="nofollow noreferrer">[very simple]</a> </p> <p>Ok Chad check here the code :</p> <p>Main Activity :</p> <pre><code>package org.example.chad; import java.util.ArrayList; import android.app.ListActivity; import android.os.Bundle; public class MainActivity extends ListActivity { private ArrayList&lt;DataItem&gt; data = new ArrayList&lt;DataItem&gt;(); @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); //create Objects DataItem obj1 = new DataItem("name1", "record1"); DataItem obj2 = new DataItem("name2", "record2"); DataItem obj3 = new DataItem("name3", "record3"); DataItem obj4 = new DataItem("name4", "record4"); DataItem obj5 = new DataItem("name5", "record5"); //add the to ArrayList data.add(obj1); data.add(obj2); data.add(obj3); data.add(obj4); data.add(obj5); CustomAdapter adapter = new CustomAdapter(this, R.layout.row, data); setListAdapter(adapter); } </code></pre> <p>}</p> <p><strong>main.xml</strong> :</p> <pre><code>&lt;RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" android:layout_height="match_parent" tools:context=".MainActivity" &gt; &lt;ListView android:id="@android:id/list" android:layout_width="fill_parent" android:layout_height="fill_parent" /&gt; &lt;/RelativeLayout&gt; </code></pre> <p><strong>DataItem</strong> :</p> <pre><code>package org.example.chad; public class DataItem { private String name; private String record; public DataItem(){ } public DataItem(String n, String r ){ this.name = n; this.record = r; } public String getname() { return name; } public void setname(String name) { this.name = name; } public String getrecord() { return record; } public void setrecord(String record) { this.record = record; } </code></pre> <p>}</p> <p>CustomAdapter :</p> <pre><code>package org.example.chad; import java.util.ArrayList; import android.content.Context; import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; import android.widget.ArrayAdapter; import android.widget.TextView; public class CustomAdapter extends ArrayAdapter&lt;DataItem&gt; { private ArrayList&lt;DataItem&gt; objects; public CustomAdapter(Context context, int textViewResourceId, ArrayList&lt;DataItem&gt; objects) { super(context, textViewResourceId, objects); this.objects = objects; } @Override public View getView(int position, View convertView, ViewGroup parent) { View v = convertView; if (v == null) { LayoutInflater inflater = (LayoutInflater) getContext().getSystemService(Context.LAYOUT_INFLATER_SERVICE); v = inflater.inflate(R.layout.row, null); } DataItem i = objects.get(position); if (i != null) { TextView nameView = (TextView) v.findViewById(R.id.name); TextView recordView = (TextView) v.findViewById(R.id.record); if (nameView != null){ nameView.setText(i.getname()); } if (recordView != null){ recordView.setText(i.getrecord()); } } return v; } } </code></pre> <p>and <strong>row.xml</strong> :</p> <pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt; &lt;LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="match_parent" android:orientation="horizontal" &gt; &lt;TextView android:id="@+id/name" android:layout_width="100sp" android:layout_height="20sp" android:textSize="16sp" android:layout_gravity="left|center_vertical" android:layout_marginLeft="10sp"/&gt; &lt;TextView android:id="@+id/record" android:layout_width="100sp" android:layout_height="wrap_content" android:layout_marginLeft="10sp" android:layout_gravity="right" android:textSize="16sp" /&gt; &lt;/LinearLayout&gt; </code></pre> <p>In a couple of hours I will add some comments. The result is here <img src="https://i.stack.imgur.com/4ycWR.png" alt="enter image description here"></p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload