我在GridView中遇到问题,如果我在GRIDVIEW中单击图像然后在EditText中显示名称,从可绘制的NOT中从GridView名称显示。 " NOT IMAGEVIEW单击但是GRIDVIEW图像单击"
grid_view.xml:
enter code here
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical">
<GridView
android:id="@+id/grid_view"
android:layout_width="fill_parent"
android:layout_height="368dp"
android:columnWidth="90dp"
android:gravity="center"
android:horizontalSpacing="10dp"
android:numColumns="auto_fit"
android:stretchMode="columnWidth"
android:verticalSpacing="10dp"/>
<EditText
android:id="@+id/editText1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:ems="10"
android:inputType="text" />
</LinearLayout>
enter code here
ImageAdapter.Java
enter code here
package com.tes.butawarna;
import android.content.Context;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.GridView;
import android.widget.ImageView;
public class ImageAdapter extends BaseAdapter {
private Context mContext;
// Keep all Images in array
public Integer[] mThumbIds = {
R.drawable.plat_ishihara_01,
R.drawable.plat_ishihara_02,
R.drawable.plat_ishihara_04,
R.drawable.plat_ishihara_05,
R.drawable.plat_ishihara_07,
R.drawable.plat_ishihara_08,
R.drawable.plat_ishihara_09,
R.drawable.plat_ishihara_10,
};
// Constructor
public ImageAdapter(Context c){
mContext = c;
}
@Override
public int getCount() {
return mThumbIds.length;
}
@Override
public Object getItem(int position) {
return mThumbIds[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(mThumbIds[position]);
imageView.setScaleType(ImageView.ScaleType.CENTER_CROP);
imageView.setLayoutParams(new GridView.LayoutParams(70, 70));
return imageView;
}
}
AndroidGridLayout.java
enter code here
package com.tes.butawarna;
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.EditText;
import android.widget.GridView;
public class AndroidGridLayoutActivity extends Activity {
String[] nama;
EditText namagambar;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
namagambar=(EditText)findViewById(R.id.editText1);
setContentView(R.layout.grid_layout);
GridView gridView = (GridView) findViewById(R.id.grid_view);
gridView.setAdapter(new ImageAdapter(this));
gridView.setOnItemClickListener(new OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> parent, View v,
int position, long id) {
// Sending image id to FullScreenActivity
Intent i = new Intent(getApplicationContext(), Training.class);
// passing array index
i.putExtra("id", position);
startActivity(i);
}
});
}
}
答案 0 :(得分:0)
启动活动后,只显示不同的布局。只是ImageView和TextView。 第一个editText1在gridView下无用。把它放在不同的布局中。