我有以下问题。我向自己展示了一个列表,并且我已经对列表中的项目进行了单击。我希望用字符串替换项目。我的列表显示了名称和ID。我想看看如何点击10行,其中id为50,它将转到新类,在那里我需要检索该字符串,该字符串将是前一个类中的50并且全局声明。也许它会显示更多或更少:
这是我点击的位置:
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main4);
DevicesList = new ArrayList<>();
lv = (ListView) findViewById(R.id.list);
new GetDevices().execute();
button2 = (TextView) findViewById(R.id.name);
idbudynku = (TextView) findViewById(R.id.id);
ListAdapter adapter = new SimpleAdapter(Buildings.this, DevicesList,
R.layout.list_item3, new String[]{"name", "id"},
new int[]{R.id.name, R.id.id});
lv.setAdapter(adapter);
lv.setOnItemClickListener(new AdapterView.OnItemClickListener() {
public void onItemClick(AdapterView<?> parent, View view,
int position, long id) {
if (position == 0) {
Intent myIntent = new Intent(view.getContext(), Buildings_Devices.class);
startActivityForResult(myIntent, 0);
}
}
});
这里我们有一个int位置,我想用我正在下载的字符串替换:
try {
JSONObject jsonObj = new JSONObject(jsonStr);
JSONArray buildings = jsonObj.getJSONArray("list");
for (int i = 0; i < buildings.length(); i++) {
JSONObject c = buildings.getJSONObject(i);
String id = c.getString("id");
String name = c.getString("name");
HashMap<String, String> building = new HashMap<>();
building.put("id", id);
building.put("name", name);
DevicesList.add(building);
}
} catch ...
现在他只想在字符串ID的值之后才读取位置,例如50.然后他将转到新的类,你必须保留下载字符串值的信息,这样我才能继续使用那个价值