【发布时间】:2015-09-14 11:58:11
【问题描述】:
我在从 gridview 获取文本时遇到一些问题,并最终以新的意图使用 putextra 将它们传递给另一个活动,但每次我尝试获取文本应用程序时都会停止。这是代码
public class MainActivity extends ActionBarActivity {
String cJSON;
private ProgressDialog pDialog;
GridView gvColl;
private static final String TAG_RESULTS = "result";
private static final String TAG_ID = "ID";
private static final String TAG_NAME = "Nome";
JSONArray worker_lst = null;
ArrayList<HashMap<String, String>> tableColl = new ArrayList<HashMap<String, String>>();
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
gvColl = (GridView) this.findViewById(R.id.gvCollab);
tableColl = new ArrayList<HashMap<String,String>>();
getData();
}
protected void showList() {
try {
JSONObject jsonObj = new JSONObject(cJSON);
worker_lst = jsonObj.getJSONArray(TAG_RESULTS);
for (int i = 0; i < worker_lst.length(); i++) {
JSONObject c = worker_lst.getJSONObject(i);
String id = c.getString(TAG_ID);
String name = c.getString(TAG_NAME);
HashMap<String, String> persons = new HashMap<String, String>();
persons.put(TAG_NAME, name);
persons.put(TAG_ID, id);
tableColl.add(persons);
}
gvColl = (GridView) findViewById(R.id.gvCollab);
gvColl.setAdapter(new JAdapter(MainActivity.this, tableColl));
gvColl.setOnItemClickListener(new AdapterView.OnItemClickListener() {
public void onItemClick(AdapterView<?> parent, View v, int position, long id) {
// this work properly. I don’t be able to get id and name from grid
Toast.makeText(getApplicationContext(), "Collaboratore Scelto : " + position, Toast.LENGTH_LONG).show();
}
});
}catch (JSONException e) {
e.printStackTrace();
}
}
【问题讨论】:
-
能否请您出示您的日志猫
-
您的应用程序在加载网格数据之前停止?请分享您遇到的例外情况