Customized Listview With Textview, Textview, Radiogroup In Android
I'm developing an application with ListView for Student Marklist creation. In this application, the List have 10 students. There are four grades provided for the exam which was con
Solution 1:
This is a sample example of custom adapter for listview. Modify it as your need: XML layout :
<?xml version="1.0" encoding="utf-8"?><LinearLayoutandroid:id="@+id/main"android:orientation="vertical"android:layout_height="fill_parent"android:layout_width="fill_parent"xmlns:android="http://schemas.android.com/apk/res/android"><!-- Header --><LinearLayoutandroid:id="@+id/header"android:layout_width="match_parent"android:layout_height="wrap_content"android:background="@color/black" ><TextViewandroid:id="@+id/item2"android:layout_width="match_parent"android:layout_height="wrap_content"android:height="30dip"android:text="Latest News - Your Healing Place"android:textAppearance="?android:attr/textAppearanceMedium"android:textColor="#FFFFFF"android:width="100dip" /><TextViewandroid:id="@+id/item1"android:layout_width="wrap_content"android:layout_height="fill_parent"android:height="30dip"android:width="20dip" /></LinearLayout><Viewandroid:layout_width="fill_parent"android:layout_height="1dip"android:background="?android:attr/listDivider" /><LinearLayoutandroid:id="@+id/layout"android:layout_width="wrap_content"android:layout_height="fill_parent"><ListViewandroid:id="@+id/listview"android:layout_width="fill_parent"android:layout_height="fill_parent"android:background="@color/black" ></ListView></LinearLayout></LinearLayout>
news.java :
List<HashMap<String, String>> fillMaps = new ArrayList<HashMap<String, String>>();
String[] from = newString[] {"details", "date"};
int[] to = newint[] { R.id.item1, R.id.item2};
ListView lv= (ListView)findViewById(R.id.listview);
HashMap<String, String> map = new HashMap<String, String>();
map.put("details", "This is a sample message");
map.put("date", "24-07-2003");
fillMaps.add(map);
SimpleAdapter adapter = new SimpleAdapter(this, fillMaps, R.layout.grid_item, from, to);
lv.setAdapter(adapter);
Solution 2:
You can use a class inheriting from ArrayAdapter, and overriding its getView() method.
publicclassStudentAdapterextendsArrayAdapter<Student> {
protected LayoutInflater inflater;
publicStudentAdapter(final Context context) {
super(context, 0);
inflater = (LayoutInflater) ((Context) context)
.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
}
public View getView(int position, View convertView, ViewGroup parent) {
// Note: You should optimize here with re-using convertViewViewrowView= inflater.inflate(R.layout.user_address_row_layout,
parent, false);
TextViewsNo= (TextView) rowView.findViewById(R.id.sNo);
sNo.setText(getItem(position).number);
// same for every field of the row// ...return rowView;
}
}
Post a Comment for "Customized Listview With Textview, Textview, Radiogroup In Android"