Sunday, 11 August 2013

checking condition for activity

checking condition for activity

I have a layout with 3 buttons Create, Show and Setting. on clicking
create and show button they are working fine and getting transferred to
next activity whatever it is. but i need to check for setting button. that
is- if password table exists then it should go to password.class and if
doesnt exists then to Setting.class.
on trying this code the else statement is showing dead code and not
responding.
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.app.Activity;
import android.content.Intent;
import android.database.Cursor;
import android.database.sqlite.SQLiteDatabase;
public class MainActivity extends Activity {
Button create, show, setting;
String pass1,pass2;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
create = (Button)findViewById(R.id.button1);
create.setOnClickListener(new View.OnClickListener() {
public void onClick(View view) {
Intent myIntent1 = new Intent(view.getContext(), Create.class);
startActivityForResult(myIntent1, 0);
}
});
show = (Button)findViewById(R.id.button2);
show.setOnClickListener(new View.OnClickListener() {
public void onClick(View view) {
Intent myIntent2 = new Intent(view.getContext(), Password.class);
startActivityForResult(myIntent2, 0);
}
});
SQLiteDatabase db = openOrCreateDatabase("passmanage", MODE_PRIVATE,
null);
Cursor c = db.rawQuery("select * from password", null);
c.moveToFirst();
if(c!=null)
{
setting = (Button)findViewById(R.id.button3);
setting.setOnClickListener(new View.OnClickListener() {
public void onClick(View view) {
Intent myIntent3 = new Intent(view.getContext(),
Password.class);
startActivityForResult(myIntent3, 0);
}
});
}
else
{
setting = (Button)findViewById(R.id.button3);
setting.setOnClickListener(new View.OnClickListener() {
public void onClick(View view) {
Intent myIntent3 = new Intent(view.getContext(),
Setting.class);
startActivityForResult(myIntent3, 0);
}
});
}
}
}

No comments:

Post a Comment