[英]i have a fragment contain List View, on a item click how to send position (int) to a new activity
我正在創建簡單的計數應用程序我創建一個主要活動包含兩個選項卡的選項卡布局然后每個選項卡包含片段上的片段我有一個列表視圖當和 onitem 單擊時我想統計一個新活動
Intent intent = new Intent(getActivity(), ButtonCountActivity.class);
startActivity(intent);
我喜歡在 ButtonCountActivity 上獲取 listView.setOnItemClickListener int 我如何?
在 newActivity 我正在計數並將計數的數據保存到 SQLdatabase 我需要這個(int i)來選擇點擊的項目來更新
在片段上
listView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> adapterView, View view, int i, long l) {
Intent intent = new Intent(getActivity(), ButtonCountActivity.class);
Bundle bundle = new Bundle();
bundle.putInt("Value",i);
startActivity(intent);
}
});
關於新活動
Intent intent= getIntent();
Bundle bundle = new Bundle();
bundle = intent.getBundleExtra("value");
int value = bundle.getInt("value");
Log.d("T","haha got u " + value );
我得到一個空值我試圖修復我的我需要幫助非常非常菜鳥
您將 int 放入“Value”並嘗試從“value”中獲取它當然會得到 null,兩者都應該是“Value”或“value”
改變這個
Intent intent = new Intent(getActivity(), ButtonCountActivity.class);
Bundle bundle = new Bundle();
bundle.putInt("Value",i);
startActivity(intent);
對此
Intent intent = new Intent(getActivity(), ButtonCountActivity.class);
intent .putExtra("Value",i);
startActivity(intent);
改變這個..
Intent intent= getIntent();
Bundle bundle = new Bundle();
bundle = intent.getBundleExtra("value");
int value = bundle.getInt("value");
Log.d("T","haha got u " + value );
對此
int value;
Bundle extras = getIntent().getExtras();
if (extras != null) {
value = extras.getInt("Value");
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.