画像をフルビューで表示し、[選択]ボタンと[キャンセル]ボタンがあるカスタムダイアログボックスを作成しようとしています。このカスタムダイアログボックスは、ユーザーが選択したイメージをフルビューで表示できるように画像がクリックされたときに表示されます。イメージビューは、GridViewから選択されたものでなければなりません。選択ボタンはトーストメッセージを表示し、キャンセルボタンはユーザがダイアログを終了できるようにする。このアイデアは、ユーザが望む画像を最終的に選択する前に、ユーザがフルビューで画像を見ることを可能にすることである。フルビュー画像を表示するカスタムダイアログボックスを作成する
しかし、私はこれをしようとするいくつかの問題があります。私のコードは以下に示されています:
package com.newapp;
import android.app.Activity;
import android.app.Dialog;
import android.content.DialogInterface;
import android.content.Context;
import android.os.Bundle;
import android.view.View;
import android.widget.AdapterView;
import android.widget.BaseAdapter;
import android.widget.GridView;
import android.widget.ImageView;
import android.widget.Toast;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.ImageView;
import android.widget.Button;
public class MainActivity extends Activity {
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
//error here: R cannot be resolved to a variable
GridView gridview = (GridView) findViewById(R.id.photogrid);
gridview.setAdapter(new ImageAdapter(this));
gridview.setOnItemClickListener(new OnItemClickListener() {
public void onItemClick(AdapterView<?> parent, View v, int position, long id) {
//Toast.makeText(MainActivity.this, "" + position, Toast.LENGTH_SHORT).show();
Context mContext = getApplicationContext();
Dialog dialog = new Dialog(mContext);
dialog.setContentView(R.layout.ImageDialog);
dialog.setTitle("Full-image view");
ImageView image = (ImageView) dialog.findViewById(R.id.image);
image.setImageResource(R.drawable.android);
Button select = (Button) findViewById(R.id.selectimage);
buttonChangePerferences.setOnClickListener(new OnClickListener() {
public void onClick(View v) {
Toast.makeText(MainActivity.this, "" + position, Toast.LENGTH_SHORT).show();
}
});
}
Button cancel = (Button) findViewById(R.id.cancelselection);
cancel.setOnClickListener(new OnClickListener()
//error here: Syntax error on tokens;AnnotationName expected instead
{
public void onClick(View v) {
dialog.cancel();
}
});
})
}
package com.newapp;
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;
public ImageAdapter(Context c) {
mContext = c;
}
public int getCount() {
return mThumbIds.length;
}
public Object getItem(int position) {
return null;
}
public long getItemId(int position) {
return 0;
}
// create a new ImageView for each item referenced by the Adapter
public View getView(int position, View convertView, ViewGroup parent) {
ImageView imageView;
if (convertView == null) { // if it's not recycled, initialize some attributes
imageView = new ImageView(mContext);
imageView.setLayoutParams(new GridView.LayoutParams(85, 85));
imageView.setScaleType(ImageView.ScaleType.CENTER_CROP);
imageView.setPadding(8, 8, 8, 8);
} else {
imageView = (ImageView) convertView;
}
imageView.setImageResource(mThumbIds[position]);
return imageView;
}
// references to our images
private Integer[] mThumbIds = {
R.drawable.sample_2, R.drawable.sample_3,
R.drawable.sample_4, R.drawable.sample_5,
R.drawable.sample_6, R.drawable.sample_7,
R.drawable.sample_0, R.drawable.sample_1,
R.drawable.sample_2, R.drawable.sample_3,
R.drawable.sample_4, R.drawable.sample_5,
R.drawable.sample_6, R.drawable.sample_7,
R.drawable.sample_0, R.drawable.sample_1,
R.drawable.sample_2, R.drawable.sample_3,
R.drawable.sample_4, R.drawable.sample_5,
R.drawable.sample_6, R.drawable.sample_7,
R.drawable.sample_0, R.drawable.sample_1,
R.drawable.sample_2, R.drawable.sample_3,
R.drawable.sample_4, R.drawable.sample_5,
R.drawable.sample_6, R.drawable.sample_7,
};
}
誰かが私にこれらの問題を解決するのを手伝ってもらえますか?どんな助けでも大歓迎です。おかげ
「問題」が何であるか把握できるはずです。解決策を見つけるのを手伝ってくれるかもしれません。 – Reno