gpt4 book ai didi

android - Intent 值分别形成包含多个值的 ListView 行

转载 作者:行者123 更新时间:2023-11-30 03:38:08 24 4
gpt4 key购买 nike

我想将包含多个值的每个 ListView 行的值分别用于另一个 Activity 。并在另一个 Activity 中分别获取 editext 中的每个值:

我的代码是:

try
{
JSONArray jArray = new JSONArray(result);
final ArrayList <String>arrayListTitle = new ArrayList<String>();
for(int i=0;i<jArray.length();i++)
{
StringBuilder s = new StringBuilder();
JSONArray innerJsonArray = jArray.getJSONArray(i);
JSONObject json_data = innerJsonArray.getJSONObject(0);
at1=json_data.getString("title");
at= json_data.getString("mdate");
at2=json_data.getString("mtime");
at3=json_data.getString("venue");
at4=json_data.getString("organiser");
arrayListTitle.add(at1);
arrayListTitle.add(at);
arrayListTitle.add(at2);
arrayListTitle.add(at3);
s.append("\nTitle:"+at1);
s.append("\ndate:"+at);
s.append("\nTime:"+at2);
s.append("\nVenue:"+at3);
s.append("\nOrganiser:"+at4);
s.append("\n");


r.add(s.toString());
}


l.setAdapter(new ArrayAdapter<String>(this, android.R.layout.simple_list_item_1, r));
l.setOnItemClickListener(new OnItemClickListener()
{
public void onItemClick(AdapterView<?> myAdapter, View myView, int myItemInt, long mylng)
{
String selectedFromList =(String) (l.getItemAtPosition(myItemInt));

// Starting new intent
intent1 = new Intent(RequestmeetActivity.this, ConfirmmeetActivity.class);


intent1.putExtra("title", arrayListTitle.get(myItemInt));
intent1.putExtra("mdate", arrayListTitle.get(myItemInt));
intent1.putExtra("mtime", arrayListTitle.get(myItemInt));
intent1.putExtra("venue", arrayListTitle.get(myItemInt));


startActivity(intent1);
}
});
}

我的 Activity 看起来像:

enter image description here

所以我想从这个 ListView 行中单独获取值,并将这些值用于另一个 Activity 。我怎样才能做到这一点。请帮助我,我是 android 的新手。提前致谢。在另一个 Activity 上

Bundle extras = getIntent().getExtras();
if(extras != null){
mtitle = extras.getString("title");
stime = extras.getString("mtime");
sdate = extras.getString("mdate");
cvenue = extras.getString("venue");
}

title.setText(mtitle);
cdate=(EditText)findViewById(R.id.editText2);
cdate.setText(sdate);
venue=(EditText)findViewById(R.id.editText4);
venue.setText(cvenue);
ctime=(EditText)findViewById(R.id.editText3);
ctime.setText(stime);

最佳答案

defind global ArrayList arrayListTitle = new ArrayList;正如您在 r 中定义的那样。并在 for 循环中附加代码之前在其中添加值。对于标题 arrayListTitle.add(at1);

ArrayList<String> arrayListTitle = new ArrayList<String>;

for(int i=0;i<jArray.length();i++) {
StringBuilder s = new StringBuilder();
JSONArray innerJsonArray = jArray.getJSONArray(i);
JSONObject json_data = innerJsonArray.getJSONObject(0);
at1=json_data.getString("title");
at= json_data.getString("mdate");
at2=json_data.getString("mtime");
at3=json_data.getString("venue");
at4=json_data.getString("organiser");
arrayListTitle.add(at1); // check this line I have added value of title in arraylist you can take it same as data and time etc.
s.append("\nTitle:"+at1);
s.append("\ndate:"+at);
s.append("\nTime:"+at2);
s.append("\nVenue:"+at3);
s.append("\nOrganiser:"+at4);
s.append("\n");
r.add(s.toString());
}

对于 ListView 项目点击:

 l.setOnItemClickListener(new OnItemClickListener() {
public void onItemClick(AdapterView<?> myAdapter,
View myView, int myItemInt, long mylng) {
String selectedFromList =(String) (l.getItemAtPosition(myItemInt));
// Starting new intent
intent1 = new Intent(RequestmeetActivity.this,
ConfirmmeetActivity.class);
intent1.putExtra("title",arrayListTitle.get(myItemInt)); // check this line get value from the arraylistTitle for the particular position.
intent1.putExtra("mdate",selectedFromList);
intent1.putExtra("uid",uid);
startActivity(intent1);
}

在另一个 Activity 中获取标题时:编写如下代码:

String title;

Bundle extras = getIntent().getExtras();
if(extras != null){
title = extras.getString("title"); // same for others
}

editTxt.setText(title);

关于android - Intent 值分别形成包含多个值的 ListView 行,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16296574/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com