帮帮我,为什么“ img.setOnLongClickListener”在此代码中不起作用? 我在屏幕上拨动很长,但是没有显示出alertdialog。
打包com.me.life;
import android.app.AlertDialog;
import android.content.DialogInterface;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.os.Bundle;
import android.os.Environment;
import android.support.annotation.Nullable;
import android.support.v7.app.AppCompatActivity;
import android.view.View;
import android.widget.EditText;
import android.widget.Toast;
import java.io.File;
公共类Show_big_image扩展了AppCompatActivity { 私有字符串表,文件夹= Environment.getExternalStorageDirectory()+“ /life/.images”; 私有String []轴名; 选择了私有int; 私有位图myBitmap; Database_class db;
@Override
protected void onCreate(@Nullable Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.show_big_image);
db = new Database_class(this);
}
@Override
protected void onResume() {
super.onResume();
selected=getIntent().getIntExtra("selectedpic", 0);
axname = getIntent().getStringArrayExtra("allpicname");
table= getIntent().getExtras().getString("table");
show_pic();
}
public void show_pic ()
{
try {
db.open();
final String toz=db.get_image_tozih(axname[selected] ,table);
db.close();
File imgFile = new File(folder +"/"+axname[selected]+".png");
myBitmap = BitmapFactory.decodeFile(imgFile.getAbsolutePath());
TouchImageView img = new TouchImageView(this);
img.setImageBitmap(myBitmap);
img.setMaxZoom(4f);
setContentView(img);
img.setOnLongClickListener(new View.OnLongClickListener() {
@Override
public boolean onLongClick(View view) {
AlertDialog.Builder alert = new AlertDialog.Builder(Show_big_image.this);
final EditText edittext = new EditText(Show_big_image.this);
edittext.setText(toz);
alert.setView(edittext);
alert.setPositiveButton("ok", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int whichButton) {
db.open();
db.edit_image_tozih(edittext.getText().toString(), axname[selected] ,table);
db.close();
show_pic();
}
});
alert.show();
return false;
}
});
img.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
AlertDialog.Builder alert = new AlertDialog.Builder(Show_big_image.this);
alert.setPositiveButton("next", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int whichButton) {
if((axname.length-selected)>=2){
myBitmap.recycle();
selected=selected+1;
show_pic();
}
}
});
alert.setNegativeButton("back", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int whichButton) {
if(selected!=0) {
myBitmap.recycle();
selected = selected - 1;
show_pic();
}
}
});
alert.show();
}
});
} catch (Exception e) {
Toast.makeText(getApplicationContext(),"error",Toast.LENGTH_SHORT).show();
}
}
@Override
protected void onPause() {
super.onPause();
myBitmap.recycle();
}
@Override
public void onBackPressed() {
super.onBackPressed();
myBitmap.recycle();
finish();
}
}