当用户单击文本视图中的值时,我试图打开一个新活动。这里的 onCreate 方法:
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
// Get change in selected projects group & show group accordingly
RadioGroup rgProjectGroupsToLoad = (RadioGroup) findViewById(R.id.rgProjectGroupsToLoad);
rgProjectGroupsToLoad.setOnCheckedChangeListener(new RadioGroup.OnCheckedChangeListener()
{
public void onCheckedChanged(RadioGroup rGroup, int checkedId)
{
// Get the vocab needed to provide options
Resources res = getResources();
String[] region_values = res.getStringArray(R.array.regions);
String[] priority_values = res.getStringArray(R.array.priorities);
String[] curr_values = region_values;
TextView tvGroupingHeader = (TextView) findViewById(R.id.listRegionsPrioritiesHeader);
RadioButton checkedRadioButton = (RadioButton)rGroup.findViewById(checkedId);
boolean isChecked = checkedRadioButton.isChecked();
if (isChecked)
{
String selected_group = (String) checkedRadioButton.getText();
Log.w("myApp", "Project Group selected: " + selected_group);
tvGroupingHeader.setText(selected_group);
if (selected_group.equals("Geographic Regions"))
{
curr_values = region_values;
}
else
{
curr_values = priority_values;
}
// Project Group Adapter for ListView
ArrayAdapter<String> proj_group_adapter = new ArrayAdapter<String>(
getBaseContext(),
android.R.layout.simple_list_item_1,
android.R.id.text1,
curr_values
);
ListView lvRegionsPriorities = (ListView) findViewById(R.id.listRegionsPriorities);
lvRegionsPriorities.setAdapter(proj_group_adapter);
// Show hidden elements
TextView tv = (TextView) findViewById(R.id.listRegionsPrioritiesHeader);
tv.setVisibility(View.VISIBLE);
ListView lv = (ListView) findViewById(R.id.listRegionsPriorities);
lv.setVisibility(View.VISIBLE);
}
}
});
}
我试过设置lvRegionsPriorities.setOnItemClickListener
,但这只会产生很多错误,我在谷歌搜索时找不到任何结果。
那么,有人可以在这里帮忙吗?如何正确设置事件监听器?
谢谢埃里克