在我的这段代码中,我想在单击时更改图像。我怎么能这样做?
我使用img.setOnClickListenser
但我真的不知道代码必须放入其中
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
View rootView = inflater.inflate(R.layout.gallery_img2, container, false);
Log.d("start_new_frg gallery_img ", "ok");
back = (Button)rootView.findViewById(R.id.button1);
if (id == -1 ){
Toast.makeText(getActivity(), "bad Entry ", Toast.LENGTH_LONG).show();
onBackPressed();
getActivity().finish();
}
imgv = (ImageView) rootView.findViewById(R.id.imageView1);
String ROOT = Environment.getExternalStorageDirectory().getPath()+"/POSTSIMAGES/";
final Bitmap image = BitmapFactory.decodeFile(ROOT+String.valueOf(g.getId())+"q.jpg");
File f = new File(ROOT+String.valueOf(g.getId())+"q.jpg");
temp=ROOT;
if(!f.exists()){
imgv.setImageResource(R.drawable.logo_and);
}
else
{
imgv.setImageBitmap(image);
}
if( isNetworkConnected( )){
new conn().execute("");
}else{
// pd.dismiss();
// if(ROOT.endsWith("_s"))
// {
//
//
// }
imgv.setOnClickListener(new OnClickListener() {
public void onClick(View v) {
// your code here
Log.d("inside onclick", "ok");
String _n=temp.replace("_s.jpg", "_n.jpg");
imageLoader2.DisplayImage(_n,imgv );
// imgv.setScaleType(ImageView.ScaleType.FIT_XY);
}
});
}
//////////////////////// ADS ///////////////////////
// Create the adView
adView = new AdView(getActivity(), AdSize.SMART_BANNER, "a150f45ea765784");
// Lookup your LinearLayout assuming it's been given
// the attribute android:id="@+id/mainLayout"
LinearLayout layout = (LinearLayout)rootView.findViewById(R.id.ADS);
// Add the adView to it
layout.addView(adView);
// Initiate a generic request to load it with an ad
adView.loadAd(new AdRequest());
//////////////////////// END ADS ///////////////////////
back.setOnClickListener(new OnClickListener() {
public void onClick(View arg0) {
Fragment newFragment = new Gallery(getActivity());
FragmentTransaction transaction = getFragmentManager().beginTransaction();
// Replace whatever is in the fragment_container view with this fragment,
// and add the transaction to the back stack
transaction.replace(android.R.id.content, newFragment);
// transaction.addToBackStack(null);
// Commit the transaction
// transaction.remove(mFragment);
transaction.commit();
}
});
return rootView;
}