所以,我的应用程序的第一个解释:主要活动应该调用第二个活动,然后实现一个片段,以显示有关列表项目单击的详细信息。所有这些似乎都没问题,但在新的活动/细节窗口中,有一个TextView,用户应该可以点击以便从“完成”更改为“未完成”,反之亦然。现在新的片段加载,但它似乎无法识别用户的交互。任何帮助,将不胜感激。谢谢!可点击TextView的Android问题
public class ListActivity extends Activity implements ListSelectionFragment.OnListFragmentInteractionListener, View.OnClickListener {
private boolean finished=FALSE;
@Override
protected void onCreate(Bundle savedInstanceState) {
ListSelectionFragment detailFrag = ListSelectionFragment.newInstance(displayMode, position, page);
FragmentManager fragmentManager = getFragmentManager();
FragmentTransaction fragmentTransaction = fragmentManager
.beginTransaction();
fragmentTransaction.add(R.id.item_frame, detailFrag);
fragmentTransaction.commit();
findViewById(R.id.item_frame).setVisibility(View.VISIBLE);
TextView textView1 = (TextView) findViewById(R.id.list_item_name);
textView1.setText(displayMode);
if(finished==TRUE) {
TextView textView2 = (TextView) findViewById(R.id.completebtn);
textView2.setText("Finished");
textView2.setTextColor(Color.parseColor("#000000"));
}
TextView completeBtn = (TextView) findViewById(R.id.completebtn);
completeBtn.setOnClickListener(this);
}
@Override
public void onClick(View v) {
TextView textView = (TextView) findViewById(R.id.completebtn);
textView.setText("Finished");
finished=TRUE;
}
}
你在哪里声明变量'finished'?并点击从完成改变到未完成的位置。 –
对不起,我剪掉那部分......我将它定义为类的布尔变量(正如在上面的代码片段的第一行下面) –
除非我错过读代码,它看起来会保持“完成”。此外,我没有看到你将onClick监听器添加到文本视图 – snowCrabs