有人可以看看我在做什么错。在方法listView之外声明了全局变量,onClickListener并尝试在方法内部为该变量分配一个值。方法内部但null外部的变量日志返回值。public static String selected;public void onItemClick(AdapterView<?> parent, View view, int position, long id) { selected = ((TextView) view.findViewById(R.id.textviewid)).getText().toString(); Toast.makeText(getApplicationContext(), selected, Toast.LENGTH_SHORT).show(); Log.i("Selected", "Value: "+selected);}});Log.i("Selected2", "Value: "+selected);日志显示:06-22 11:58:16.597 10063-10063/com.example.app I/Selected2: Value: null06-22 11:58:28.487 10063-10063/com.example.app I/Selected: Value: Value1
添加回答
举报
0/150
提交
取消