В коде, который я пишу, я намеревался открыть новое действие внутри onclicklistener, но он не работает. Другой код в слушателе работает, также, если я помещаю то же самое намерение вне слушателя в «альтернативное местоположение», это работает. Так что я не уверен, в чем проблема здесь. Я был бы очень признателен за любую помощь, спасибо.
Это код, используемый во вкладке, которая содержит кнопку, для которой написан Слушатель.
public class RemaindersPage extends Activity
{
com.commsware.pgtracker.RemainderControl rc1;
int count;
LinearLayout.LayoutParams lp1,lp2;
Button btn1,btn2,btn3;
LinearLayout ll1,ll2;
Intent i;
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.remainders);
//<Alternate Location> : Intent works if placed here
TabHost th=(TabHost)findViewById(R.id.tabhost);
th.setup();
TabHost.TabSpec spec=th.newTabSpec("tag1");
spec.setContent(R.id.tab1);
spec.setIndicator("REMAINDERS");
th.addTab(spec);
spec=th.newTabSpec("tag2");
spec.setContent(R.id.tab2);
spec.setIndicator("AUTO REMAINDERS");
th.addTab(spec);
spec=th.newTabSpec("tag3");
spec.setContent(R.id.tab3);
spec.setIndicator("USER REMAINDERS");
th.addTab(spec);
//adding remainder control
int ht=LayoutParams.WRAP_CONTENT;
int wt=LayoutParams.FILL_PARENT;
lp1=new LinearLayout.LayoutParams(wt,ht);
ll2=(LinearLayout)findViewById(R.id.tab1_ll);
//Adding Listeners for the buttons in each tab
//Tab1
btn1=(Button)findViewById(R.id.tab1_add1);
btn1.setOnClickListener(new View.OnClickListener()
{
@Override
public void onClick(View v)
{
btn1.setText("");
i=new Intent(RemaindersPage.this,weekly.class);
startActivity(i);
//AddRemainder();
}
});
//Tab2
btn2=(Button)findViewById(R.id.tab2_add2);
btn2.setOnClickListener(new View.OnClickListener()
{
@Override
public void onClick(View v)
{
btn2.setText("");
//AddRemainder();
}
});
//Tab3
btn3=(Button)findViewById(R.id.tab3_add3);
btn3.setOnClickListener(new View.OnClickListener()
{
@Override
public void onClick(View v)
{
btn3.setText("");
//AddRemainder();
}
});
}
//draw a new reminder_control instance
private void AddRemainder()
{
rc1=new com.commsware.pgtracker.RemainderControl(RemaindersPage.this);
rc1.setId(1000+count);
ll2.addView(rc1,lp1);
rc1.SetText("MESSAGE "+Integer.toString(count),0);
count++;
}
//query for all rows in the table and obtain a cursor
/*private void fillData()
{
cursor=dbHelper.fetchAllReminders();
startManagingCursor(cursor);
}
@Override
protected void onDestroy()
{
super.onDestroy();
if (dbHelper != null)
{
dbHelper.close();
}
}*/
}