ListView
2つのsで生成したいのですがTextView
、各行(2つのテキストビュー)は薄い仕切りで分割されています....しかし、アダプターは仕切りを返しません-textViewsのみ...だから私は何をしますか...
私は2つのテキストビュー(タイトルと日付)を持つメッセージのリストビューを持っています...これはxmlです -pthy_messages_list_item.xml ....
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:padding="10dp"
android:background="@drawable/list_item_selector" >
<TextView
android:id="@+id/mess_name"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="5dp"
android:layout_marginBottom="5dp"
android:textSize="20sp"
android:textColor="@drawable/list_item_textselector" />
<TextView
android:id="@+id/mess_date"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_alignParentTop="true"
android:layout_marginTop="5dp"
android:layout_marginBottom="5dp"
android:textSize="20sp"
android:textColor="@drawable/list_item_textselector"/>
<View
android:id="@+id/m_devider"
android:layout_width="1dp"
android:layout_height="fill_parent"
android:layout_alignParentTop="true"
android:layout_toLeftOf="@+id/mess_date"
android:background="@color/greydevider" />
そして別のxmlから-リストビュー...
<LinearLayout
android:layout_width="match_parent"
android:layout_height="fill_parent"
android:background="#333333"
android:orientation="vertical" >
<ListView
android:id="@android:id/list"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:footerDividersEnabled="true"
android:divider="#757575"
android:dividerHeight="0.5dp"
/>
<View
android:id="@+id/view1"
android:layout_width="wrap_content"
android:layout_height="0.5dp"
android:background="#757575" />
</LinearLayout>
アクティビティからこのリストビューを作成します...
public class MessagesActivity extends ListActivity {
//ArrayList<HashMap<String, String>> menuList;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.pthy_mess);
Mess menu_data[] = new Mess[]
{
new Mess("first", "01.12.13", R.color.greydevider),
new Mess("second", "11.12.13", R.color.greydevider),
new Mess("third", "21.12.13", R.color.greydevider)
};
MessAdapter adapter = new MessAdapter(getApplicationContext(),
R.layout.pthy_messages_list_item, menu_data);
final ListView listView1 = getListView();
listView1.setAdapter(adapter);
listView1.setOnItemClickListener(new OnItemClickListener() {
public void onItemClick(AdapterView<?> parent, View v,
int position, long id) {
String selitem = listView1.getItemAtPosition(position).toString();
Log.v("CLICKED", selitem);
}
});
}
}
そしてMess.javaのコード-
public class Mess {
// public int icon;
public String title;
public String date;
public int devider;
public Mess(){
super();
}
public Mess(String title, String date, int devider) {
super();
this.devider = devider;
this.title = title;
this.date = date;
}
@Override
public String toString() {
return this.title;
}
}
そしてMessAdapter.java -
public class MessAdapter extends ArrayAdapter<Mess>{
Context context;
int layoutResourceId;
Mess data[] = null;
public MessAdapter(Context context, int layoutResourceId, Mess[] data) {
super(context, layoutResourceId, data);
this.layoutResourceId = layoutResourceId;
this.context = context;
this.data = data;
}
@Override
public View getView(int position, View convertView, ViewGroup parent) {
View row = convertView;
MenuHolder holder = null;
if(row == null)
{
// LayoutInflater inflater = ((Activity)context).getLayoutInflater();
LayoutInflater inflater = (LayoutInflater) context
.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
row = inflater.inflate(layoutResourceId, parent, false);
holder = new MenuHolder();
holder.txtTitle = (TextView)row.findViewById(R.id.mess_name);
holder.txtDate = (TextView)row.findViewById(R.id.mess_date);
holder.devider = (View)row.findViewById(R.id.m_devider);
row.setTag(holder);
}
else
{
holder = (MenuHolder)row.getTag();
}
Mess xxx = data[position];
holder.txtTitle.setText(xxx.title);
holder.txtDate.setText(xxx.date);
return row;
}
@Override
public int getCount() {
return data.length;
}
static class MenuHolder
{
TextView txtTitle;
TextView txtDate;
View devider;
}
}