我想在我的listView中選擇多個項目,並將它們發送到另一個listView點擊一個按鈕的活動。我會提供一些代碼,但我現在很無助,無法在任何地方找到答案。當我運行我的應用程序時,就UI而言,一切都看起來很好。與內部列表視圖我想在我的listView中選擇多個項目,並通過單擊按鈕將它們發送到另一個活動中的另一個listView
.xml文件:
<ListView
android:id="@+id/beerProduct"
android:layout_width="wrap_content"
android:layout_height="0dp"
android:layout_weight="0.28" >
</ListView>
<Button
android:id="@+id/addtolist"
style="?android:attr/borderlessButtonStyle"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:minHeight="75dp"
android:onClick="sendMessage"
android:text="@string/addtolist"
android:textSize="26sp" />
</LinearLayout>
的.java調用列表視圖: 包com.practice.practiceapp1;
import android.os.Bundle;
import android.support.v7.app.ActionBarActivity;
import android.view.Menu;
import android.view.MenuItem;
import android.widget.ArrayAdapter;
import android.widget.ListView;
// Array of options --> Array Adapter --> ListView
public class Beer<object> extends ActionBarActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_beer);
populateListView();
}
private void populateListView() {
// create list of items
String[] beerItems = { "Miller Chill", "Miller Fortune",
"Miller Genuine Draft", "Miller High Life",
"Miller High Life Light", "Miller Lite", "Miller 64",
"Milwaukee\'s Best Ice", "Milwaukee\'s Best Light",
"Milwaukee\'s Best Premium" };
// build adapter
final ArrayAdapter<String> adapter = new ArrayAdapter<String>(this,
R.layout.beer_items, beerItems);
// configure the ListView
final ListView list = (ListView) findViewById(R.id.beerProduct);
list.setAdapter(adapter);
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.beer, menu);
return true;
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
// Handle action bar item clicks here. The action bar will
// automatically handle clicks on the Home/Up button, so long
// as you specify a parent activity in AndroidManifest.xml.
int id = item.getItemId();
if (id == R.id.action_settings) {
return true;
}
return super.onOptionsItemSelected(item);
}
}
包含的.xml列表視圖屬性:
<?xml version="1.0" encoding="utf-8"?>
<TextView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:minHeight="75dp"
android:textSize="26sp" >
</TextView>
謝謝!
里根
這很廣泛。你堅持哪部分?你應該首先重寫'OnItemSelected'。並看看[CHOICE_MODE_MUKTIPLE](http://developer.android.com/reference/android/widget/AbsListView.html#attr_android:choiceMode) – codeMagic 2014-10-17 13:54:08
搜索「CAB android」(是的,它可以用於support.v7 ) – Selvin 2014-10-17 14:09:48