Reputation: 333
After hours of searching, I cannot find anyone who has the similar problem as mine, could you kindly support me for this problem, please.
I have an activity with two listview: listview1 is placed above listview2.
This is my activity:
private ListView mListApplication_kid, mListApplication_non_kid;
private List<ResolveInfo> mListAplicationInfo;
private List<MyApplication> mListApplicationList = new ArrayList<MyApplication>();
private List<MyApplication> mListApplicationList_non_kid = new ArrayList<MyApplication>();
private KidModeAdapter1 mAplicationAdapter;
private KidModeAdapter2 mAplicationAdapter_non_default;
private Context mContext;
private String TAG = "KidModeActivity";
@Override
protected void onCreate(Bundle arg0) {
// TODO Auto-generated method stub
super.onCreate(arg0);
setContentView(R.layout.activity_kid_mode);
mContext=this;
list_kid_mode = new ArrayList<String>(Arrays.asList(PHONE, CONTACTS, MESSAGE, CAMERA, CHROME));
mListApplication_kid = (ListView) findViewById(R.id.listview_kidmode_default);
mListApplication_non_kid = (ListView) findViewById(R.id.listview_kidmode_non_default);
loadAplication();
}
private void loadAplication() {
mAplicationAdapter = new KidModeAdapter1(mContext, R.layout.aplication_item, mListApplicationList);
mAplicationAdapter_non_default = new KidModeAdapter2(mContext, R.layout.aplication_item, mListApplicationList_non_kid);
mListApplicationList.removeAll(mListApplicationList);
mListApplicationList_non_kid.removeAll(mListApplicationList_non_kid);
mAplicationAdapter.notifyDataSetChanged();
mAplicationAdapter_non_default.notifyDataSetChanged();
new loadKidMode().execute(); // load all the available MyApplication into the mListApplicationList, and mListApplicationList_non_kid
mListApplication_kid.setAdapter(mAplicationAdapter);
mListApplication_non_kid.setAdapter(mAplicationAdapter_non_default);
}
and this is my xml file:
<?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/txtKidMode"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true"
android:layout_marginTop="5dp"
android:gravity="center"
android:text="@string/default_mode"
android:textColor="@color/title"
android:textSize="@dimen/title_textsize" />
<ListView
android:id="@+id/listview_kidmode_default"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@color/counter_text_color"
android:clickable="true">
</ListView>
<ListView
android:id="@+id/listview_kidmode_non_default"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="10dp"
android:background="@color/list_background"
android:clickable="true">
</ListView>
</LinearLayout>
I know it is about this activity and setting up the KidModeAdapter1 and KidModeAdapter2 files, but just don't know how. Could you kindly help me, please !!!
Upvotes: 0
Views: 88
Reputation: 3274
You should set OnItemClickListener
to the ListView
that you want to click:
mListApplication_kid.setOnItemClickListener(new OnItemClickListener(){
@Override
public void onItemClick(AdapterView<?> parent, View view, int position,
long id) {
mListApplicationList_non_kid.add(parent.getItemAtPosition(position));
mAplicationAdapter_non_default.notifyDataSetChanged();
mListApplicationList.remove(parent.getItemAtPosition(position));
mApplicationAdapter.notifyDataSetChanged();
}
});
This will remove the item from one ListView
and insert the same item in the other ListView
when the item is clicked.
EDIT
If you have other elements which request focus in your list item, add android:focusable="false"
to them
Upvotes: 1