我正在获取图像数组作为响应,并在全屏显示并滑动它,但如果我的图像数组为null我需要禁用点击事件并阻止它进入下一个活动,我尝试了很多但不知道是什么在我的代码中出错。请按照我的代码进行操作.. https://stackoverflow.com/questions/27458980/how-to-send-response-to-next-activity/27498613?noredirect=1#comment43428525_27498613
public class Profile extends Activity{
private ProgressDialog pDialog;
AQuery androidAQuery=new AQuery(this);
private static final String USER_NAME="name";
private static final String USER_AGE="age";
private static final String USER_LOCATION="location";
private static final String USER_MOTHER_TONGE="mother_tounge";
private static final String USER_OCCU="occupation";
private static final String USER_INCOM="income";
private static final String USER_HEIGHT="height";
private static final String USER_CAST="cast";
private static final String USER_MARRAGE="marital_status";
private static final String USER_RELIGION="religion";
private static final String USER_GOTRA="gotra";
private static final String USER_MANGLIK="manglik";
private static final String USER_RASHI="rashi";
private static final String USER_EDUCATION="education";
private static final String USER_EAT="eating";
private static final String USER_DRINK="drink";
private static final String USER_SMOKE="smoke";
private static final String USER_ABOUT="about_me";
private static final String USER_PIC="profile_pic";
private static final String USER_IMG="user_image";
private static String USER_URL="";
private ImageView btnedit;
private TextView uname;
private TextView fdetail;
private TextView sdetail;
private TextView tdetail;
private TextView ocdetail;
private TextView incomedetail;
private TextView uheight;
private TextView umrg;
private TextView ureligion;
private TextView ugotra;
private TextView umanglik;
private TextView urashi;
private TextView udegree;
private TextView ueat;
private TextView udrink;
private TextView usmoke;
private TextView uabout;
private ImageView ucover;
private TextView occu_second;
private TextView place_second;
String user_name;
String user_age;
String user_location;
String user_mothertong;
String user_occupation;
String user_income;
String user_height;
String user_cast;
String user_marg;
String user_religion;
String user_gotra;
String user_manglik;
String user_rashi;
String user_education;
String user_eat;
String user_drink;
String user_smoke;
String user_about;
String user_pro;
private TextView age_sceond;
private TextView ucast;
String marital;
String user_img;
@Override
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
setContentView(R.layout.profile_edit);
String matchId=this.getIntent().getStringExtra("id");
USER_URL=""+matchId;
//Toast.makeText(ProfilePage.this,"match id blank",Toast.LENGTH_LONG).show();
StrictMode.ThreadPolicy policy = new StrictMode.ThreadPolicy.Builder().permitAll().build();
StrictMode.setThreadPolicy(policy);
ServiceHandler sh = new ServiceHandler();
// Making a request to url and getting response
String jsonStr = sh.makeServiceCall(USER_URL, ServiceHandler.GET);
Log.d("Response: ", "> " + jsonStr);
try {
JSONObject jsonObj = new JSONObject(jsonStr);
user_name = jsonObj.getString(USER_NAME);
user_age = jsonObj.getString(USER_AGE);
user_location = jsonObj.getString(USER_LOCATION);
user_mothertong = jsonObj.getString(USER_MOTHER_TONGE);
user_occupation = jsonObj.getString(USER_OCCU);
user_income = jsonObj.getString(USER_INCOM);
user_height = jsonObj.getString(USER_HEIGHT);
user_cast=jsonObj.getString(USER_CAST);
user_marg = jsonObj.getString(USER_MARRAGE);
user_religion = jsonObj.getString(USER_RELIGION);
user_gotra = jsonObj.getString(USER_GOTRA);
user_manglik = jsonObj.getString(USER_MANGLIK);
user_rashi = jsonObj.getString(USER_RASHI);
user_education = jsonObj.getString(USER_EDUCATION);
user_eat = jsonObj.getString(USER_EAT);
user_drink = jsonObj.getString(USER_DRINK);
user_smoke = jsonObj.getString(USER_SMOKE);
user_about = jsonObj.getString(USER_ABOUT);
user_pro = jsonObj.getString(USER_PIC);
user_img=jsonObj.getString(USER_IMG);
user_img = "";
JSONArray picarray = (JSONArray) jsonObj.get("user_image");
for(int i=0;i< picarray.length();i++)
{
user_img+= picarray.getString(i);
Log.d("mylog", "curent pro pic = " + user_img);
}
Log.d("mylog", "all images = " + user_img);
uname = (TextView)findViewById(R.id.namedetail);
fdetail = (TextView)findViewById(R.id.firstdetail);
sdetail = (TextView)findViewById(R.id.seconddetail);
tdetail = (TextView)findViewById(R.id.thirddetail);
ocdetail=(TextView)findViewById(R.id.txtoccupationdetail);
incomedetail = (TextView)findViewById(R.id.incomedetaile);
uheight = (TextView)findViewById(R.id.txtheightprofile);
ucast=(TextView)findViewById(R.id.usercast);
umrg = (TextView)findViewById(R.id.txtmrgprofile);
ureligion = (TextView)findViewById(R.id.prohindu);
ugotra = (TextView)findViewById(R.id.gothraa);
umanglik = (TextView)findViewById(R.id.usermanglik);
urashi = (TextView)findViewById(R.id.rashi);
udegree = (TextView)findViewById(R.id.userdegree);
ueat = (TextView)findViewById(R.id.txteatprofile);
udrink = (TextView)findViewById(R.id.txtdrinkprofile);
usmoke = (TextView)findViewById(R.id.txtsmokeprofile);
uabout = (TextView)findViewById(R.id.txtabouther);
ucover = (ImageView)findViewById(R.id.coverimage);
age_sceond=(TextView)findViewById(R.id.txtageprofile);
occu_second=(TextView)findViewById(R.id.txtworkingprofile);
place_second=(TextView)findViewById(R.id.txtplaceprofile);
if(user_name.equals(""))
{
uname.setText("Not willing to specify");
}
else
{
uname.setText(user_name);
}
if(user_age.equals(""))
{
fdetail.setText("Not willing to specify");
age_sceond.setText("Not willing to specify");
}
else
{
fdetail.setText(user_age+" years");
age_sceond.setText(user_age+" years");
}
if(user_location.equals(""))
{
sdetail.setText("Not willing to specify");
place_second.setText("Not willing to specify");
}
else
{
sdetail.setText(user_location);
place_second.setText(user_location);
}
if(user_mothertong.equals(""))
{
tdetail.setText("Not willing to specify");
}
else
{
tdetail.setText(user_mothertong);
}
if(user_occupation.equals(""))
{
ocdetail.setText("Not willing to specify");
occu_second.setText("Not willing to specify");
}
else
{
ocdetail.setText(user_occupation);
occu_second.setText(user_occupation);
}
if(user_income.equals(""))
{
incomedetail.setText("Not willing to specify");
}
else
{
incomedetail.setText(user_income);
}
if(user_height.equals(""))
{
uheight.setText("Not willing to specify");
}
else
{
uheight.setText(user_height);
}
if(user_cast.equals(""))
{
ucast.setText("Not willing to specify");
}
else
{
ucast.setText(user_cast);
}
if(user_marg.equals(""))
{
umrg.setText("Not willing to specify");
}
else
{
umrg.setText(user_marg);
}
if(user_religion.equals(""))
{
ureligion.setText("Not willing to specify");
}
else
{
ureligion.setText(user_religion);
}
if(user_gotra.equals(""))
{
ugotra.setText("Not willing to specify");
}
else
{
ugotra.setText(user_gotra);
}
if(user_manglik.equals(""))
{
umanglik.setText("Not willing to specify");
}
else
{
umanglik.setText(user_manglik);
}
if(user_rashi.equals(""))
{
urashi.setText("Not willing to specify");
}
else
{
urashi.setText(user_rashi);
}
if(user_education.equals(""))
{
udegree.setText("Not willing to specify");
}
else
{
udegree.setText(user_education);
}
if(user_eat.equals(""))
{
ueat.setText("Not willing to specify");
}
else
{
ueat.setText(user_eat);
udrink.setText(user_drink);
usmoke.setText(user_smoke);
}
if(user_about.equals(""))
{
uabout.setText("Not willing to specify");
}
else
{
uabout.setText(user_about);
}
androidAQuery.id(ucover).image(user_pro, true, true);
} catch (JSONException e) {
e.printStackTrace();
}
ucover.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
Intent i = new Intent(getApplicationContext(), Fullimage.class);
i.putExtra("images", USER_IMG);
startActivity(i);
}
});
btnedit=(ImageView)findViewById(R.id.editprofilebutton);
btnedit.setOnClickListener(new OnClickListener() {
@SuppressWarnings("deprecation")
@Override
public void onClick(View arg0)
{
AlertDialog.Builder builder = new AlertDialog.Builder(ProfileEdit.this);
builder.setTitle(R.string.title_alertbox)
.setIcon(R.drawable.ic_launcher)
.setMessage(R.string.chek)
.setCancelable(true)
.setNegativeButton(R.string.okalert, new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int id) {
dialog.dismiss();
}
});
AlertDialog welcomeAlert = builder.create();
welcomeAlert.show();
// Make the textview clickable. Must be called after show()
((TextView)welcomeAlert.findViewById(android.R.id.message)).setMovementMethod(LinkMovementMethod.getInstance());
/*// Creating alert Dialog with one Button
AlertDialog alertDialog = new AlertDialog.Builder(
ProfileEdit.this).create();
// Setting Dialog Title
alertDialog.setTitle("Edit Profile");
// Setting Dialog Message
alertDialog.setMessage("Please log on to gujjumatch.com desktop site to edit your profile " +
"and also set other details or call on 91 281 3054120");
// Setting Icon to Dialog
alertDialog.setIcon(R.drawable.ic_launcher);
// Setting OK Button
alertDialog.setButton("OK",
new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog,
int which) {
// Write your code here to execute after dialog
// closed
Toast.makeText(getApplicationContext(),
"Thank You", Toast.LENGTH_SHORT)
.show();
}
});
// Showing Alert Message
alertDialog.show();*/
}
});
}
fullimageview
public class FuLLimage extends Activity{
private String strtd;
String[] imgStr;
@Override
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
setContentView(R.layout.full_image_view);
strtd=this.getIntent().getStringExtra("images");
System.out.println("imagess..........." + strtd);
imgStr = strtd.split(",");
System.out.println("Image String Array : " + imgStr);
ViewPager viewPager = (ViewPager) findViewById(R.id.view_pager);
ImageAdapter adapter = new ImageAdapter(this);
viewPager.setAdapter(adapter);
ImageView imageView = (ImageView) findViewById(R.id.full_image_view);
}
public class ImageAdapter extends PagerAdapter {
Context context;
ImageAdapter(Context context)
{
this.context=context;
}
@Override
public int getCount() {
return imgStr.length;
}
@Override
public boolean isViewFromObject(View view, Object object) {
return view == ((ImageView) object);
}
@Override
public Object instantiateItem(ViewGroup container, int position) {
ImageView imageView = new ImageView(context);
int padding = context.getResources().getDimensionPixelSize(R.dimen.activity_horizontal_margin);
imageView.setPadding(padding, padding, padding, padding);
imageView.setScaleType(ImageView.ScaleType.FIT_CENTER);
imageView.setImageBitmap(BitmapFactory.decodeFile(imgStr[position]));
//imageView.setImageURI(Uri.parse(imgStr[position]));
((ViewPager) container).addView(imageView, 0);
return imageView;
}
@Override
public void destroyItem(ViewGroup container, int position, Object object) {
((ViewPager) container).removeView((ImageView) object);
}
}
}
答案 0 :(得分:0)
检查您的数组长度,如果它不为零则启用onclicklistener ..
if(picarray.length != 0)
{
ucover.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
Intent i = new Intent(getApplicationContext(), Fullimage.class);
i.putExtra("images", USER_IMG);
startActivity(i);
}
});
}
答案 1 :(得分:0)
您可以检查您的arraylist的长度,然后根据该设置向用户发送消息
if(picarray.length()!=0)
{
ucover.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
Intent i = new Intent(getApplicationContext(), Fullimage.class);
i.putExtra("images", USER_IMG);
startActivity(i);
}
});
}
else
{//show your message here
}
答案 2 :(得分:0)
您可以将侦听器设置为null以禁用onclick事件
ucover.setOnClickListener(null)
如果您想恢复点击活动,只需致电
ucover.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
Intent i = new Intent(getApplicationContext(), Fullimage.class);
i.putExtra("images", USER_IMG);
startActivity(i);
}
});
提供此帮助。