custom.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/textView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="TextView" />
<TextView
android:id="@+id/textView2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="TextView" />
</LinearLayout>
<?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/textView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="TextView" />
<TextView
android:id="@+id/textView2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="TextView" />
</LinearLayout>
---------------------------------------------------------------------------------------------------------------
customactivity.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" >
<ListView
android:id="@+id/listView1"
android:layout_width="match_parent"
android:layout_height="wrap_content" >
</ListView>
</LinearLayout>
---------------------------------------------------------------------------------------------------------------
public class CusActvity extends Activity{
String[] names = {"name1", "name2", "name3", "name4", "name5", "nam6","name7", "name8", "name9", "name10" };
String[] locations = { "location1", "location2", "location3", "location4","location5", "location6", "location7", "location8", "location9","location10" };
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.customactivity);
ListView list = (ListView) findViewById(R.id.listView1);
raja ca = new raja();
list.setAdapter(ca);
}
public class raja extends BaseAdapter{
@Override
public int getCount() {
// TODO Auto-generated method stub
return 5;
}
@Override
public Object getItem(int position) {
// TODO Auto-generated method stub
return null;
}
@Override
public long getItemId(int position) {
// TODO Auto-generated method stub
return 0;
}
@Override
public View getView(int position, View convertView, ViewGroup parent) {
convertView = getLayoutInflater().inflate(R.layout.custom, null);
TextView t1 = (TextView)convertView.findViewById(R.id.textView1);
TextView t2 = (TextView)convertView.findViewById(R.id.textView2);
t1.setText(names[position]);
t2.setText(locations[position]);
// TODO Auto-generated method stub
return convertView;
}
}
}
No comments:
Post a Comment