我不知道如何写我的问题,所以我希望你能从我的代码中理解: 所以我有这个示例代码:
MAIN:
public class ListImageButton extends Activity {
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.list);
ListView lv = (ListView) findViewById( R.id.list );
lv.setOnItemClickListener(
new OnItemClickListener() {
public void onItemClick(AdapterView<?> arg0,
android.view.View arg1, int arg2, long arg3) {
//HERE THIS IS WORKING
boolean_toast = false;
timer.cancel();
zanimivosti.cancel();
Intent intent = new Intent(ListImageButton.this,
ANOTHER_ACTIVITY.class);
startActivity(intent);
}
});
ArrayList<String> items = new ArrayList<String>();
items.add( "item1");
items.add( "item2");
ListAdapter adapter = new ListAdapter( this, items);
lv.setAdapter( adapter );
}
}
适配器:
public class ListAdapter extends BaseAdapter {
public ListAdapter(Context context,
List<String> items ) {
inflater = LayoutInflater.from( context );
this.context = context;
this.items = items;
}
public int getCount() {
return items.size();
}
public Object getItem(int position) {
return items.get(position);
}
public long getItemId(int position) {
return position;
}
public View getView(int position, View convertView, ViewGroup parent) {
String item = items.get(position);
View v = null;
if( convertView != null )
v = convertView;
else
v = inflater.inflate( R.layout.item, parent, false);
TextView itemTV = (TextView)v.findViewById( R.id.item);
itemTV.setText( item );
ImageButton button =
(ImageButton)v.findViewById( R.id.button);
button.setOnClickListener(
new OnClickListener() {
public void onClick(View v) {
//HERE THIS IS NOT WORKING
boolean_toast = false;
timer.cancel();
zanimivosti.cancel();
Intent intent = new Intent(ListImageButton.this,
ANOTHER_ACTIVITY.class);
startActivity(intent);
}
});
return v;
}
private Context context;
private List<String> items;
private LayoutInflater inflater;
}
所以我想停止一些计时器并取消我在主要活动/课程中的一些吐司,而且我想开始一个新的活动。
答案 0 :(得分:0)
好的,我想到了,答案非常简单。看起来好像我已经厌倦了考虑它。 我在主要活动中做了这个功能:
public static void preklopi() {
boolean_toast = false;
cas = 0;
perioda = 0;
timer.cancel();
zanimivosti.cancel();
Intent intent = new Intent(Context, kasper.api.Najdi_osebo.class);
Context.startActivity(intent);
}
然后我从另一个类的主要活动中调用了该函数..