我击中了一座砖瓦墙,我接着只是把图像放在点击上。
我想要做的是,对每一个形象来说,它开启了不同的活动。
比如,algebra图像打开了algebraactive,在点击露天活动等时,精度图像。
这可能很简单,但我目前并不十分清楚。
这里是主要活动。
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.GridView;
public class MathsSubjectsActivity extends Activity {
// Keep all Images in array
public Integer[] mThumbIds = {
R.drawable.algebraicon,R.drawable.coordsicon,
R.drawable.decimalsicon,R.drawable.fractionsicon,
R.drawable.algebraicon,R.drawable.algebraicon,
R.drawable.powersicon,R.drawable.algebraicon,
R.drawable.coordsicon,R.drawable.algebraicon,
};
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.subjects);
GridView gridView = (GridView) findViewById(R.id.grid_view);
// Instance of ImageAdapter Class
gridView.setAdapter(new ImageAdapter(this,mThumbIds));
/** * On Click event for Single Gridview Item * */
gridView.setOnItemClickListener(new OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> parent, View v, int position, long id) {
switch(position)
{
case 0:
Intent login = new Intent(getApplicationContext(), MathsAlgebraActivity.class);
login.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
startActivity(login);
break;
case 1:
Intent coords = new Intent(getApplicationContext(), MathsMultiActivity.class);
coords.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
startActivity(coords);
break;
case 2:
Intent decim = new Intent(getApplicationContext(), MathsMultiActivity.class);
decim.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
startActivity(decim);
break;
//and so on for other activities.
default:
break;
}
}
});
}
}
以下是处理图像的图像改编器。
import android.content.Context;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.GridView;
import android.widget.ImageView;
private Context mContext;
private Integer[] resIds;
//Constructor
public ImageAdapter(Context c,Integer[] resIds){
mContext = c;
this.resIds=resIds;
}
@Override
public int getCount() {
return resIds.length;
}
@Override
public Object getItem(int position) {
return resIds[position];
}
@Override
public long getItemId(int position) {
return 0;
}
@Override
public View getView(int position, View convertView, ViewGroup parent) {
ImageView imageView = new ImageView(mContext);
imageView.setImageResource(resIds[position]);
imageView.setScaleType(ImageView.ScaleType.CENTER_CROP);
imageView.setLayoutParams(new GridView.LayoutParams(70, 70));
return imageView;
}
}
案件0,但不1或2。
误差:
Thread [<1> main] (Suspended (exception ActivityNotFoundException))
Instrumentation.checkStartActivityResult(int, Object) line: 1405
Instrumentation.execStartActivity(Context, IBinder, IBinder, Activity, Intent, int) line: 1379
MathsSubjectsActivity(Activity).startActivityForResult(Intent, int) line: 2827
MathsSubjectsActivity(Activity).startActivity(Intent) line: 2933
MathsSubjectsActivity$1.onItemClick(AdapterView, View, int, long) line: 51
GridView(AdapterView).performItemClick(View, int, long) line: 284
AbsListView$PerformClick.run() line: 1812
ViewRoot(Handler).handleCallback(Message) line: 587
ViewRoot(Handler).dispatchMessage(Message) line: 92
Looper.loop() line: 130
ActivityThread.main(String[]) line: 3683
Method.invokeNative(Object, Object[], Class, Class[], Class, int, boolean) line: not available [native method]
Method.invoke(Object, Object...) line: 507
ZygoteInit$MethodAndArgsCaller.run() line: 839
ZygoteInit.main(String[]) line: 597
NativeStart.main(String[]) line: not available [native method]