我在定制cwac touchlistview时遇到问题。我的代码几乎与示例相同。唯一的区别是我使用自定义arraylist而不是字符串列表。
我注意到几个问题:
任何想法我应该改变什么?
import com.commonsware.cwac.tlv.TouchListView;
public class Reorder extends ListActivity{
ArrayList<Message> list = new ArrayList<Message>();
private CustomAdapter myAdapter;
@Override
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
setContentView(R.layout.maincommit);
prekopiraj();
TouchListView tlv=(TouchListView)getListView();
myAdapter = new CustomAdapter();
setListAdapter(myAdapter);
tlv.setDropListener(onDrop);
tlv.setRemoveListener(onRemove);
}
private void prekopiraj(){
for(int i = 0; i<WaitingRoom.messagescopy.size(); i++){
list.add(WaitingRoom.messagescopy.get(i));
}
}
private TouchListView.DropListener onDrop=new TouchListView.DropListener() {
@Override
public void drop(int from, int to) {
Message item=myAdapter.getItem(from);
myAdapter.remove(item);
myAdapter.insert(item, to);
}
};
private TouchListView.RemoveListener onRemove=new TouchListView.RemoveListener() {
@Override
public void remove(int which) {
myAdapter.remove(myAdapter.getItem(which));
}
};
private class CustomAdapter extends ArrayAdapter<Message>{
CustomAdapter() {
super(Reorder.this, R.layout.rowcommit, list);
}
@Override
public View getView(int position, View convertView, ViewGroup parent) {
View v = convertView;
if (v == null) {
LayoutInflater inflater=getLayoutInflater();
v=inflater.inflate(R.layout.rowcommit, parent, false);
}
Message o;
o = list.get(position);
if (o != null) {
TextView tt = (TextView) v.findViewById(R.id.textView111);
TextView bt = (TextView) v.findViewById(R.id.textView112);
TextView te = (TextView) v.findViewById(R.id.textView113);
TextView rt = (TextView) v.findViewById(R.id.textView114);
ImageView iv = (ImageView) v.findViewById(R.id.imageView4);
if (tt != null) {
tt.setText("ID: " +Integer.toString(o.getorder_id()) + " Ura: " + o.gettime());
}
if(bt != null){
bt.setText(o.getcustomer_address());
}
if(te != null) {
te.setText(o.getphone());
}
if(rt != null){
rt.setText(o.getfood_order());
}
}
return(v);
}
}
@Override
protected void onListItemClick(ListView l, View v, int position, long id) {
// TODO Auto-generated method stub
super.onListItemClick(l, v, position, id);
String selection = l.getItemAtPosition(position).toString();
Toast.makeText(this, selection, Toast.LENGTH_LONG).show();
}
}
XML的一部分
<com.commonsware.cwac.tlv.TouchListView
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tlv="http://schemas.android.com/apk/res/com.lightcone.mapoverlaydemo"
android:id="@+id/@android:list"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:drawSelectorOnTop="false"
tlv:normal_height="70sp"
tlv:grabber="@+id/icon"
tlv:remove_mode="slideRight"
/>