私はTextViewを含むListViewしか持っていません。リストの各行に画像とボタンを追加して、ボタンをクリックすると、SimpleCursorAdapterから取得したデータを送信し、別のアクティビティに移動させます。SimpleCursorAdapterを使用した、テキストイメージとボタン付きのアンドロイドリストビュー
私は2つのxmlファイルを持っています。 ListViewを含むものと、他のxmlファイルには、TextView、ImageView、Buttonが含まれています。
私はstackoverflowとオンラインで多くの記事を読んでいますが、私はまだそれを働かせることはできません。私は、ボタンのgetView()、onClickListenerと関係があるものがあると思いますが、SimpleCursorAapterクラスとリンクする方法はわかりません。私の場合と同じように、私はSimpleCursorAdapterを拡張せずに直接使用しました。私はそれがボタンと画像を含むXMLファイルにアクセスする方法を混乱させる。現在のコードは次のとおりです。
public class BoardsActivity extends ListActivity {
private static final int ACTIVITY_SUBSCRIBE = 0;
private AnnouncementDbAdapter dbAdapter;
private Cursor cursor;
private Button subscribeButton;
//private LayoutInflater mInflater;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.subscribe_to);
// mInflater = (LayoutInflater) getSystemService(Activity.LAYOUT_INFLATER_SERVICE);
dbAdapter = new AnnouncementDbAdapter(this);
// dbAdapter.open();
// fillData();
@Override
protected void onResume() {
super.onResume();
dbAdapter.open();
fillData();
@Override
protected void onPause() {
super.onPause();
dbAdapter.close();
private void fillData() {
cursor = dbAdapter.fetchAllBoards();
startManagingCursor(cursor);
String[] from = new String[] {AnnouncementDbHelper.BNAME };
int[] to = new int[] {R.id.subscribeactivity_bname};
SimpleCursorAdapter board = new SimpleCursorAdapter(this,R.layout.subscribe_to_row, cursor, from, to);
setListAdapter(board);
@Override
protected void onListItemClick(ListView l, View v, int position, long id) {
super.onListItemClick(l, v, position, id);
Cursor details = dbAdapter.fetchBoard(id);
startManagingCursor(details);
Intent i = new Intent(this, BoardDetailsActivity.class);
i.putExtra(AnnouncementDbHelper.BID, id);
startActivityForResult(i, ACTIVITY_SUBSCRIBE);
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent intent) {
super.onActivityResult(requestCode, resultCode, intent);
dbAdapter.open();
fillData();}
画像をDrawablesから取得するにはどうすればいいですか?ユーザーがボタンをクリックすると、別のアクティビティに移動しますか?
は、そのリンクをお試しくださいチェック?あなたが何か難しいと感じる場合は、Lemmeが知っている – Venky