Wondering how I would code a listview with 2 textviews per row of the list view.
my row is going to have the xml layout like this:
simple_list_item_1.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<TextView android:id="@+id/stat_name"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:padding="10dip"
android:textSize="16dip"
android:textStyle="bold"/>
<TextView
android:id="@+id/stat_number"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:padding="10dip"
android:textSize="16dip"
android:textStyle="bold"
android:layout_below="@id/stat_name"/>
</LinearLayout>
The code I have so far is:
public class PlayerActivity extends Activity {
public Elements name;
public Elements num;
public ArrayList<String> statName = new ArrayList<String>();
public ArrayList<String> statNum = new ArrayList<String>();
private ArrayAdapter<String> nameAdapter;
private ArrayAdapter<String> numAdapter;
private ListView lv;
String url = "http://www.futhead.com/14/players/141/andrea-pirlo/";
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.player);
lv = (ListView) findViewById(R.id.listView);
new Logo().execute();
new statistics().execute();
nameAdapter = new ArrayAdapter<String>(this, R.layout.simple_list_item_1, R.id.stat_name,statName);
numAdapter = new ArrayAdapter<String>(this, R.layout.simple_list_item_1, R.id.stat_number,statNum);
}
private class statistics extends AsyncTask<String, Void, String> {
@Override
protected String doInBackground(String... arg) {
Document document;
try {
document = Jsoup.connect(url).get();
num = document.select("div#stats-base p");
statNum.clear();
for (Element element : num) {
statNum.add(element.ownText());
}
name = document.select("div#stats-base span");
statName.clear();
for (Element element : name) {
statName.add(element.ownText());
}
} catch (IOException e) {
e.printStackTrace();
}
return null;
}
@Override
protected void onPostExecute(String result) {
lv.setAdapter(nameAdapter);
lv.setAdapter(numAdapter);
}
}
I was using a normal ArrayAdapter at first until I realized that it did not support anymore than one textview so I was wondering how I would implement an Array adapter that could support the two textviews.