Thursday, July 14, 2011

Prev and Next msg

Onclick:



String split="";String[] split_value=null;

split=(String) v.getTag();

split_value=split.split("<>");

msg_cureentposition=Integer.parseInt(split_value[1]);

Bundle bundle=new Bundle();
Intent intent=new Intent(Aajtak.this,news_Details.class);

if(msg_cureentposition==msg_length-1)
bundle.putBoolean("nextFlag",false);
else
bundle.putBoolean("nextFlag",true);

if(msg_cureentposition==0)
bundle.putBoolean("previousFlag",false);
else
bundle.putBoolean("previousFlag",true);

bundle.putString("storyId",split_value[0]);
intent.putExtras(bundle);
startActivityForResult(intent, 100);



OnActivity:


/**
* OnActivity Result to handle All Child Activity Returned result
*/

protected void onActivityResult(int requestCode, int resultCode, Intent data) {

if(resultCode==202){
//Next
msg=url[++msg_cureentposition];

Intent i=new Intent(Aajtak.this,news_Details.class);

Bundle bundle = new Bundle();
if(msg_cureentposition==msg_length-1)
bundle.putBoolean("nextFlag",false);
else
bundle.putBoolean("nextFlag",true);

if(msg_cureentposition==0)
bundle.putBoolean("previousFlag",false);
else
bundle.putBoolean("previousFlag",true);

bundle.putString("storyId",msg);
i.putExtras(bundle);
startActivityForResult(i,100);


}else if(resultCode==201){
//Previous

msg=url[--msg_cureentposition];
Intent i=new Intent(Aajtak.this,news_Details.class);
Bundle bundle = new Bundle();

if(msg_cureentposition==msg_length-1)
bundle.putBoolean("nextFlag",false);
else
bundle.putBoolean("nextFlag",true);

if(msg_cureentposition==0)
bundle.putBoolean("previousFlag",false);
else
bundle.putBoolean("previousFlag",true);

bundle.putString("storyId",msg);
i.putExtras(bundle);
startActivityForResult(i,100);


}
}
}



Next Class;

next.setOnClickListener(new OnClickListener() {

@Override
public void onClick(View v) {
// TODO Auto-generated method stub
if(next_flag)
{

previous.setVisibility(View.VISIBLE);
setResult(202);
finish();
}else{
next.setVisibility(View.INVISIBLE);
Toast.makeText(getApplicationContext(), "Last News", Toast.LENGTH_SHORT).show();
}
}

});
previous.setOnClickListener(new OnClickListener() {

@Override
public void onClick(View v) {
// TODO Auto-generated method stub
if( pre_flag)
{
next.setVisibility(View.VISIBLE);
setResult(201);
finish();
}else{
previous.setVisibility(View.INVISIBLE);
Toast.makeText(getApplicationContext(), "First News", Toast.LENGTH_SHORT).show();
}
}
});

No comments:

Post a Comment