0
私はAndroidが初めてです。私の要件は、リストビューのアイテムをチェックすることです。次のアクティビティで選択したアイテムを表示したいと思います。どのように私はアンドロイドの次の活性のリストビューのチェック項目を表示できますか?
あなたのリストビューの各行を表すXMLレイアウト、のはrow.xmlそれを呼びましょう:
誰も私を助けることができる。..事前
私はAndroidが初めてです。私の要件は、リストビューのアイテムをチェックすることです。次のアクティビティで選択したアイテムを表示したいと思います。どのように私はアンドロイドの次の活性のリストビューのチェック項目を表示できますか?
あなたのリストビューの各行を表すXMLレイアウト、のはrow.xmlそれを呼びましょう:
誰も私を助けることができる。..事前
で
ありがとうございます3つの事を作成する必要があります。リストビューを表示するに
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/myRow"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<CheckBox
android:id="@+id/myCheckbox"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:checked="false"/>
<TextView
android:text="Hello"
android:id="@+id/myText"
android:layout_width="wrap_content"
android:layout_height="wrap_content"/>
</LinearLayout>
ListActivity(または定期的な活動):あなたは「R.layout.row」として、Javaでそれにアクセスできるようにそれはあなたの/ resを/レイアウトフォルダに配置する必要があります。
public class MyActivity extends ListActivity {
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.my_activity_layout);
ArrayList<MyObjectType> data = new ArrayList<MyObjectType>();
// Populate your data list here
MyCustomAdapter adapter = new MyCustomAdapter(this, data);
setListAdapter(adapter);
}
はその後、あなたはタイプMyObjectTypeのオブジェクトを表示する方法について説明し、カスタムアダプタを設計する必要があります。
public class MyAdapter extends BaseAdapter{
private LayoutInflater inflater;
private ArrayList<MyObjectType> data;
public EventAdapter(Context context, ArrayList<MyObjectType> data){
// Caches the LayoutInflater for quicker use
this.inflater = LayoutInflater.from(context);
// Sets the events data
this.data= data;
}
public int getCount() {
return this.data.size();
}
public URL getItem(int position) throws IndexOutOfBoundsException{
return this.data.get(position);
}
public long getItemId(int position) throws IndexOutOfBoundsException{
if(position < getCount() && position >= 0){
return position;
}
}
public int getViewTypeCount(){
return 1;
}
public View getView(int position, View convertView, ViewGroup parent){
MyObjectType myObj = getItem(position);
if(convertView == null){ // If the View is not cached
// Inflates the Common View from XML file
convertView = this.inflater.inflate(R.layout.row, null);
}
((TextView)convertView.findViewById(R.id.myText)).setText(myObj.getTextToDisplay());
return convertView;
}
}
これは、あなたが始める必要があり、あなたがより多くの説明が必要な場合はコメント。