Transfer data between EditText and Text View in different activities - android

I am novice for android app development. I have an issue here.
In 1st activity, i have created 10 rows. Each row contain a next button which links to second activity.
In 2nd activity,i have edittext field to input user details such as account name, password and etc. Each time I update my account name, when i press android back button, the row should contain the updated name. But I am not able to pass the account name to the 1st activity.
Below is my code for 1st activity:
public class AccountSetup extends Activity {
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.account_main);
this.initViews();
}
private void initViews(){
TextView user1 = (TextView)findViewById(R.id.user1);
Button iconNext1 = (Button)findViewById(R.id.iconNext1);
iconNext1.setOnClickListener(new OnClickListener() {
public void onClick(View v) {
Intent Intent1 = new Intent(AccountSetup.this, AccountSettingActivity1.class);
Intent1.putExtra("rowid","1");
startActivityForResult(Intent1, 100);
}
});
Button iconNext2 = (Button)findViewById(R.id.iconNext2);
iconNext2.setOnClickListener(new OnClickListener() {
public void onClick(View v) {
Intent Intent2 = new Intent(AccountSetup.this, AccountSettingActivity2.class);
startActivity(Intent2);
finish();
}
});
Button iconNext3 = (Button)findViewById(R.id.iconNext3);
iconNext3.setOnClickListener(new OnClickListener() {
public void onClick(View v) {
Intent Intent3 = new Intent(AccountSetup.this, AccountSettingActivity3.class);
//onNewIntent((Intent) v.getTag());
Intent3.putExtra("rowid","3");
startActivity(Intent3);
finish();
}
});
Button iconNext4 = (Button)findViewById(R.id.iconNext4);
iconNext4.setOnClickListener(new OnClickListener() {
public void onClick(View v) {
Intent Intent4 = new Intent(AccountSetup.this, AccountSettingActivity4.class);
//onNewIntent((Intent) v.getTag());
Intent4.putExtra("rowid","4");
startActivity(Intent4);
finish();
}
});
Button iconNext5 = (Button)findViewById(R.id.iconNext5);
iconNext5.setOnClickListener(new OnClickListener() {
public void onClick(View v) {
Intent Intent5 = new Intent(AccountSetup.this, AccountSettingActivity5.class);
//onNewIntent((Intent) v.getTag());
Intent5.putExtra("rowid","5");
startActivity(Intent5);
finish();
}
});
Button iconNext6 = (Button)findViewById(R.id.iconNext6);
iconNext6.setOnClickListener(new OnClickListener() {
public void onClick(View v) {
Intent Intent6 = new Intent(AccountSetup.this, AccountSettingActivity6.class);
//onNewIntent((Intent) v.getTag());
Intent6.putExtra("rowid","6");
startActivity(Intent6);
finish();
}
});
Button iconNext7 = (Button)findViewById(R.id.iconNext7);
iconNext7.setOnClickListener(new OnClickListener() {
public void onClick(View v) {
Intent Intent7 = new Intent(AccountSetup.this, AccountSettingActivity7.class);
//onNewIntent((Intent) v.getTag());
Intent7.putExtra("rowid","7");
startActivity(Intent7);
finish();
}
});
Button iconNext8 = (Button)findViewById(R.id.iconNext8);
iconNext8.setOnClickListener(new OnClickListener() {
public void onClick(View v) {
Intent Intent8 = new Intent(AccountSetup.this, AccountSettingActivity8.class);
//onNewIntent((Intent) v.getTag());
Intent8.putExtra("rowid","8");
startActivity(Intent8);
finish();
}
});
Button iconNext9 = (Button)findViewById(R.id.iconNext9);
iconNext9.setOnClickListener(new OnClickListener() {
public void onClick(View v) {
Intent Intent9 = new Intent(AccountSetup.this, AccountSettingActivity9.class);
//onNewIntent((Intent) v.getTag());
Intent9.putExtra("rowid","9");
startActivity(Intent9);
finish();
}
});
Button iconNext10 = (Button)findViewById(R.id.iconNext10);
iconNext10.setOnClickListener(new OnClickListener() {
public void onClick(View v) {
Intent Intent10 = new Intent(AccountSetup.this, AccountSettingActivity10.class);
//onNewIntent((Intent) v.getTag());
Intent10.putExtra("rowid","10");
startActivity(Intent10);
finish();
}
});
}
#Override
public void onBackPressed() {
Intent i = new Intent(AccountSetup.this, WelcomeActivity.class);
startActivity(i);
finish();
super.onBackPressed();
}
#Override
protected void onActivityResult(int requestCode,int resultCode, Intent data) {
if (requestCode == 100) {
if (resultCode == RESULT_OK) {
String accountName1 = data.getStringExtra("accountName1");
}
}
}
}
And the following is the code for 2nd activity.
public class AccountSettingActivity1 extends Activity{
private EditText etAccountName;
private EditText etWanIp;
private EditText etLocalIp;
private EditText etPort;
private EditText etPassword;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.account_tab_content_setting);
this.initViews();
}
private void initViews(){
etAccountName = (EditText)this.findViewById(R.id.etAccountName);
etWanIp = (EditText)this.findViewById(R.id.etWanIp);
etLocalIp = (EditText)this.findViewById(R.id.etLocalIp);
etPort = (EditText)this.findViewById(R.id.etPort);
etPassword = (EditText)this.findViewById(R.id.etPassword);
// Assigns value
SharedPreferences sp = PreferenceManager.getDefaultSharedPreferences(this);
etAccountName.setText(sp.getString("accountName1", ""));
etWanIp.setText(sp.getString("wanIp1", ""));
etLocalIp.setText(sp.getString("localIp1", ""));
etPort.setText(sp.getString("port1", ""));
etPassword.setText(sp.getString("password1", ""));
etWanIp.setOnFocusChangeListener(new OnFocusChangeListener(){
#Override
public void onFocusChange(View arg0, boolean hasFocus) {
if(!hasFocus){
System.out.println("lost focus");
AccountSettingActivity1.this.saveSettings();
}
}
});
}
private void saveSettings(){
String accountName1 = etAccountName.getText().toString();
String wanIp1 = etWanIp.getText().toString();
String localIp1 = etLocalIp.getText().toString();
String port1 = etPort.getText().toString();
String password1 = etPassword.getText().toString();
accountName1 = (accountName1.trim().length() == 0)? "User": accountName1;
wanIp1 = (wanIp1.trim().length() == 0)? "0.0.0.0": wanIp1;
localIp1 = (localIp1.trim().length() == 0)? "0.0.0.0": localIp1;
port1 = (port1.trim().length() == 0)? "8000": port1;
password1 = (password1.trim().length() == 0)? "xxxx": password1;
etAccountName.setText(accountName1);
etWanIp.setText(wanIp1);
etLocalIp.setText(localIp1);
etPort.setText(port1);
etPassword.setText(password1);
SharedPreferences.Editor editor = PreferenceManager
.getDefaultSharedPreferences(this).edit();
editor.putString("accountName1", etAccountName.getText().toString());
editor.putString("wanIp1", etWanIp.getText().toString());
editor.putString("localIp1", etLocalIp.getText().toString());
editor.putString("port1", etPort.getText().toString());
editor.putString("password1", etPassword.getText().toString());
editor.commit();
}
/* #Override
public void onBackPressed() {
saveSettings();
Intent i = new Intent(AccountSettingActivity1.this, AccountSetup.class);
startActivity(i);
finish();
super.onBackPressed();
}*/
public void onBackPressed() {
saveSettings();
//final EditText Eclass1;
EditText et = (EditText)findViewById(R.id.etAccountName);
String s= et.getText().toString();
Intent i = new Intent(AccountSettingActivity1.this, AccountSetup.class);
i.putExtra("accountName1" ,s);
setResult(RESULT_OK, i);
finish();
super.onBackPressed();
}
#Override
protected void onPause() {
// When user leaves this tab, saves the values
this.saveSettings();
super.onPause();
}
}
1st activity xml code:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:AccountSetup="http://schemas.android.com/apk/res/com.example.play"
android:id="#+id/linearLayout1"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" >
<!-- Account Toolbar -->
<RelativeLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:background="#324F85" >
<Button
android:layout_width="54dp"
android:layout_height="30dp"
android:layout_alignParentLeft="true"
android:background="#drawable/ic_btn_done"
android:layout_centerVertical="true"/>
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="#string/selectAccount"
android:textAppearance="?android:attr/textAppearanceMedium"
android:textSize="15dp"
android:layout_centerHorizontal="true"
android:layout_centerVertical="true"
android:gravity="center"
android:textStyle="bold" />
<Button
android:id="#+id/btnAdd"
android:layout_width="54dp"
android:layout_height="30dp"
android:layout_alignParentRight="true"
android:background="#drawable/ic_btn_add_account"
android:layout_centerVertical="true" />
<ImageView
android:layout_width="4dp"
android:layout_height="30dp"
android:layout_alignTop="#+id/btnDone"
android:layout_toRightOf="#+id/btnDone"
android:src="#drawable/toolbar_seperator" />
<ImageView
android:layout_width="4dp"
android:layout_height="30dp"
android:layout_alignTop="#+id/btnAdd"
android:layout_toLeftOf="#+id/btnAdd"
android:src="#drawable/toolbar_seperator" />
</RelativeLayout>
<RelativeLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:paddingLeft="15dp"
android:paddingRight="15dp"
android:background="#drawable/logo_small_white" >
<ScrollView
android:layout_width="fill_parent"
android:layout_height="fill_parent" >
<TableLayout
android:id="#+id/tlStatus"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:stretchColumns="1" >
<TableRow
style="#style/tableRow"
android:id="#+id/row1"
android:layout_width="wrap_content"
android:layout_height="50dp"
android:layout_weight="1"
android:gravity="center_vertical" >
<TextView
android:id="#+id/user1"
style="#style/textSettingLabel"
android:layout_weight="1" />
<Button
android:id="#+id/iconNext1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="right"
android:layout_weight="1"
android:background="#drawable/icon_next" />
</TableRow>
<View style="#style/tableRowBorder" />
<TableRow
style="#style/tableRow"
android:layout_width="wrap_content"
android:layout_height="50dp"
android:layout_weight="1"
android:gravity="center_vertical" >
<TextView
android:id="#+id/user2"
style="#style/textSettingLabel"
android:layout_weight="1" />
<Button
android:id="#+id/iconNext2"
android:layout_width="wrap_content"
android:layout_gravity="right"
android:layout_weight="1"
android:scaleType="fitEnd"
android:background="#drawable/icon_next" />
</TableRow>
<View style="#style/tableRowBorder" />
<TableRow
style="#style/tableRow"
android:layout_width="wrap_content"
android:layout_height="50dp"
android:layout_weight="1"
android:gravity="center_vertical" >
<TextView
android:id="#+id/user3"
style="#style/textSettingLabel"
android:layout_weight="1" />
<Button
android:id="#+id/iconNext3"
android:layout_width="wrap_content"
android:layout_gravity="right"
android:layout_weight="1"
android:scaleType="fitEnd"
android:background="#drawable/icon_next" />
</TableRow>
<View style="#style/tableRowBorder" />
<TableRow
style="#style/tableRow"
android:layout_width="wrap_content"
android:layout_height="50dp"
android:layout_weight="1"
android:gravity="center_vertical" >
<TextView
android:id="#+id/user4"
style="#style/textSettingLabel"
android:layout_weight="1" />
<Button
android:id="#+id/iconNext4"
android:layout_width="wrap_content"
android:layout_gravity="right"
android:layout_weight="1"
android:scaleType="fitEnd"
android:background="#drawable/icon_next" />
</TableRow>
<View style="#style/tableRowBorder" />
<TableRow
style="#style/tableRow"
android:layout_width="wrap_content"
android:layout_height="50dp"
android:layout_weight="1"
android:gravity="center_vertical" >
<TextView
style="#style/textSettingLabel"
android:id="#+id/user5"
android:layout_alignBaseline="#+id/etZone_1_1"
android:text="User 1" />
<Button
android:id="#+id/iconNext5"
android:layout_width="wrap_content"
android:layout_gravity="right"
android:layout_weight="1"
android:scaleType="fitEnd"
android:background="#drawable/icon_next" />
</TableRow>
<View style="#style/tableRowBorder" />
<TableRow
style="#style/tableRow"
android:layout_width="wrap_content"
android:layout_height="50dp"
android:layout_weight="1"
android:gravity="center_vertical" >
<TextView
style="#style/textSettingLabel"
android:id="#+id/user6"
android:layout_alignBaseline="#+id/etZone_1_1"
android:text="User 1" />
<Button
android:id="#+id/iconNext6"
android:layout_width="wrap_content"
android:layout_gravity="right"
android:layout_weight="1"
android:scaleType="fitEnd"
android:background="#drawable/icon_next" />
</TableRow>
<View style="#style/tableRowBorder" />
<TableRow
style="#style/tableRow"
android:layout_width="wrap_content"
android:layout_height="50dp"
android:layout_weight="1"
android:gravity="center_vertical" >
<TextView
style="#style/textSettingLabel"
android:id="#+id/user7"
android:layout_alignBaseline="#+id/etZone_1_1"
android:text="User 1" />
<Button
android:id="#+id/iconNext7"
android:layout_width="wrap_content"
android:layout_gravity="right"
android:layout_weight="1"
android:scaleType="fitEnd"
android:background="#drawable/icon_next" />
</TableRow>
<View style="#style/tableRowBorder" />
<TableRow
style="#style/tableRow"
android:layout_width="wrap_content"
android:layout_height="50dp"
android:layout_weight="1"
android:gravity="center_vertical" >
<TextView
style="#style/textSettingLabel"
android:id="#+id/user8"
android:layout_alignBaseline="#+id/etZone_1_1"
android:text="User 1" />
<Button
android:id="#+id/iconNext8"
android:layout_width="wrap_content"
android:layout_gravity="right"
android:layout_weight="1"
android:scaleType="fitEnd"
android:background="#drawable/icon_next" />
</TableRow>
<View style="#style/tableRowBorder" />
<TableRow
style="#style/tableRow"
android:layout_width="wrap_content"
android:layout_height="50dp"
android:layout_weight="1"
android:gravity="center_vertical" >
<TextView
style="#style/textSettingLabel"
android:id="#+id/user9"
android:layout_alignBaseline="#+id/etZone_1_1"
android:text="User 1" />
<Button
android:id="#+id/iconNext9"
android:layout_width="wrap_content"
android:layout_gravity="right"
android:layout_weight="1"
android:scaleType="fitEnd"
android:background="#drawable/icon_next" />
</TableRow>
<View style="#style/tableRowBorder" />
<TableRow
style="#style/tableRow"
android:layout_width="wrap_content"
android:layout_height="50dp"
android:layout_weight="1"
android:gravity="center_vertical" >
<TextView
style="#style/textSettingLabel"
android:id="#+id/user10"
android:layout_alignBaseline="#+id/etZone_1_1"
android:text="User 1" />
<Button
android:id="#+id/iconNext10"
android:layout_width="wrap_content"
android:layout_gravity="right"
android:layout_weight="1"
android:scaleType="fitEnd"
android:background="#drawable/icon_next" />
</TableRow>
<View style="#style/tableRowBorder" />
</TableLayout>
</ScrollView>
</RelativeLayout>
</LinearLayout>
2nd activity's xml code:
<?xml version="1.0" encoding="UTF-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:ToolBar="http://schemas.android.com/apk/res/com.example.play"
xmlns:TextViewMyRiadPro="http://schemas.android.com/apk/res/com.example.play"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical">
<ViewSwitcher
android:id="#+id/switcher"
android:layout_width="fill_parent"
android:layout_height="fill_parent" >
<ScrollView
android:id="#+id/settingsView"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="#drawable/logo_small_white" >
<RelativeLayout
android:layout_width="fill_parent"
android:layout_height="565dp"
android:padding="15dp" >
<TextView
android:id="#+id/tvAccount"
android:text="Name"
android:layout_alignBaseline="#+id/etAccountName"
style="#style/textSettingLabel" />
<EditText
android:id="#+id/etAccountName"
style="#style/textSettingEdit"
android:layout_alignLeft="#+id/etWanIp"
android:inputType="text" />
<TextView
android:id="#+id/tvAccount"
android:layout_below="#+id/etAccountName"
android:text="User Account Name"
style="#style/textSettingHint" />
<TextView
android:id="#+id/tvWan"
android:text="Wan IP"
android:layout_alignBaseline="#+id/etWanIp"
style="#style/textSettingLabel" />
<EditText
android:id="#+id/etWanIp"
android:layout_below="#+id/tvAccount"
android:layout_toRightOf="#+id/tvWan"
style="#style/textSettingEdit" android:inputType="text"/>
<TextView
android:id="#+id/tvWanHint"
android:layout_below="#+id/etWanIp"
android:text="Port forwarding is required in order to establish connection from the internet"
style="#style/textSettingHint" />
<TextView
android:id="#+id/tvLocal"
android:text="Local IP"
android:layout_alignBaseline="#+id/etLocalIp"
style="#style/textSettingLabel" />
<EditText
android:id="#+id/etLocalIp"
android:layout_below="#+id/tvWanHint"
android:layout_toRightOf="#+id/tvLocal"
style="#style/textSettingEdit" android:inputType="text"/>
<TextView
android:id="#+id/tvLocalHint"
android:layout_below="#+id/etLocalIp"
android:text="The IP address of the alarm system in the local area network. 192.168.1.234 is the default address."
style="#style/textSettingHint" />
<TextView
android:id="#+id/tvPort"
android:text="Port"
android:layout_alignBaseline="#+id/etPort"
style="#style/textSettingLabel" />
<EditText
android:id="#+id/etPort"
android:layout_below="#+id/tvLocalHint"
android:layout_toRightOf="#+id/tvPort"
android:inputType="number"
style="#style/textSettingEdit" />
<TextView
android:id="#+id/tvPortHint"
android:layout_below="#+id/etPort"
android:text="The connection port of the alarm system. 8000 is the default port."
style="#style/textSettingHint" />
<TextView
android:id="#+id/tvPassword"
android:text="Password"
android:layout_alignBaseline="#+id/etPassword"
style="#style/textSettingLabel" />
<EditText
android:id="#+id/etPassword"
android:layout_below="#+id/tvPortHint"
android:layout_toRightOf="#+id/tvPassword"
style="#style/textSettingEdit" android:inputType="textPassword"/>
<TextView
android:layout_below="#+id/etPassword"
android:id="#+id/tvPasswordHint"
android:text="Your 4 digits password to access the alarm system."
style="#style/textSettingHint" />
</RelativeLayout>
</ScrollView>
</ViewSwitcher>
</LinearLayout>

use startActivityForResult() to start your 2nd activity
startActivityForResult(intent, requestcode)
When the second activity is finished do the following, the intent can hold the values that you need to pass back to activity1
setResult(RESULT_OK, intent)
finish();
now on Activity1, override onActivityResult()
onActivityResult()
{
//update your textview here.
}

deepdroid's Answer is true but you have one other alternative
Set public static String value=null; So , its will not depend on whole activity.

Related

Default pin lock screen layout

I want to provide lock screen, so every time user opens my app, he will be forced to enter pin. So I am looking for Android's default pin lock layout (as shown on image), which should work from Android 4.0. Can you tell me where to find layout of this or how to implement it properly?
I git below project from github and little changed it to provide a GUI like your image :
https://github.com/chinloong/Android-PinView
so create a project and in mainActivity insert this codes:
public class PinEntryView extends Activity {
String userEntered;
String userPin="8888";
final int PIN_LENGTH = 4;
boolean keyPadLockedFlag = false;
Context appContext;
TextView titleView;
TextView pinBox0;
TextView pinBox1;
TextView pinBox2;
TextView pinBox3;
TextView statusView;
Button button0;
Button button1;
Button button2;
Button button3;
Button button4;
Button button5;
Button button6;
Button button7;
Button button8;
Button button9;
Button button10;
Button buttonExit;
Button buttonDelete;
EditText passwordInput;
ImageView backSpace;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
appContext = this;
userEntered = "";
requestWindowFeature(Window.FEATURE_NO_TITLE);
getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
WindowManager.LayoutParams.FLAG_FULLSCREEN);
setContentView(R.layout.main_layout);
//Typeface xpressive=Typeface.createFromAsset(getAssets(), "fonts/XpressiveBold.ttf");
statusView = (TextView) findViewById(R.id.statusview);
passwordInput = (EditText) findViewById(R.id.editText);
backSpace = (ImageView) findViewById(R.id.imageView);
buttonExit = (Button) findViewById(R.id.buttonExit);
backSpace.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View view) {
passwordInput.setText(passwordInput.getText().toString().substring(0,passwordInput.getText().toString().length()-2));
}
});
buttonExit.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
//Exit app
Intent i = new Intent();
i.setAction(Intent.ACTION_MAIN);
i.addCategory(Intent.CATEGORY_HOME);
appContext.startActivity(i);
finish();
}
}
);
//buttonExit.setTypeface(xpressive);
buttonDelete = (Button) findViewById(R.id.buttonDeleteBack);
buttonDelete.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
if (keyPadLockedFlag == true)
{
return;
}
if (userEntered.length()>0)
{
userEntered = userEntered.substring(0,userEntered.length()-1);
passwordInput.setText("");
}
}
}
);
titleView = (TextView)findViewById(R.id.time);
//titleView.setTypeface(xpressive);
View.OnClickListener pinButtonHandler = new View.OnClickListener() {
public void onClick(View v) {
if (keyPadLockedFlag == true)
{
return;
}
Button pressedButton = (Button)v;
if (userEntered.length()<PIN_LENGTH)
{
userEntered = userEntered + pressedButton.getText();
Log.v("PinView", "User entered="+userEntered);
//Update pin boxes
passwordInput.setText(passwordInput.getText().toString()+"*");
passwordInput.setSelection(passwordInput.getText().toString().length());
if (userEntered.length()==PIN_LENGTH)
{
//Check if entered PIN is correct
if (userEntered.equals(userPin))
{
statusView.setTextColor(Color.GREEN);
statusView.setText("Correct");
Log.v("PinView", "Correct PIN");
finish();
}
else
{
statusView.setTextColor(Color.RED);
statusView.setText("Wrong PIN. Keypad Locked");
keyPadLockedFlag = true;
Log.v("PinView", "Wrong PIN");
new LockKeyPadOperation().execute("");
}
}
}
else
{
//Roll over
passwordInput.setText("");
userEntered = "";
statusView.setText("");
userEntered = userEntered + pressedButton.getText();
Log.v("PinView", "User entered="+userEntered);
//Update pin boxes
passwordInput.setText("8");
}
}
};
button0 = (Button)findViewById(R.id.button0);
//button0.setTypeface(xpressive);
button0.setOnClickListener(pinButtonHandler);
button1 = (Button)findViewById(R.id.button1);
//button1.setTypeface(xpressive);
button1.setOnClickListener(pinButtonHandler);
button2 = (Button)findViewById(R.id.button2);
//button2.setTypeface(xpressive);
button2.setOnClickListener(pinButtonHandler);
button3 = (Button)findViewById(R.id.button3);
//button3.setTypeface(xpressive);
button3.setOnClickListener(pinButtonHandler);
button4 = (Button)findViewById(R.id.button4);
//button4.setTypeface(xpressive);
button4.setOnClickListener(pinButtonHandler);
button5 = (Button)findViewById(R.id.button5);
//button5.setTypeface(xpressive);
button5.setOnClickListener(pinButtonHandler);
button6 = (Button)findViewById(R.id.button6);
//button6.setTypeface(xpressive);
button6.setOnClickListener(pinButtonHandler);
button7 = (Button)findViewById(R.id.button7);
//button7.setTypeface(xpressive);
button7.setOnClickListener(pinButtonHandler);
button8 = (Button)findViewById(R.id.button8);
//button8.setTypeface(xpressive);
button8.setOnClickListener(pinButtonHandler);
button9 = (Button)findViewById(R.id.button9);
//button9.setTypeface(xpressive);
button9.setOnClickListener(pinButtonHandler);
buttonDelete = (Button)findViewById(R.id.buttonDeleteBack);
//buttonDelete.setTypeface(xpressive);
}
#Override
public void onBackPressed() {
// TODO Auto-generated method stub
//App not allowed to go back to Parent activity until correct pin entered.
return;
//super.onBackPressed();
}
#Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
//getMenuInflater().inflate(R.menu.activity_pin_entry_view, menu);
return true;
}
private class LockKeyPadOperation extends AsyncTask<String, Void, String> {
#Override
protected String doInBackground(String... params) {
for(int i=0;i<2;i++) {
try {
Thread.sleep(1000);
} catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
return "Executed";
}
#Override
protected void onPostExecute(String result) {
statusView.setText("");
//Roll over
passwordInput.setText("");
;
userEntered = "";
keyPadLockedFlag = false;
}
#Override
protected void onPreExecute() {
}
#Override
protected void onProgressUpdate(Void... values) {
}
}
}
then create main_layout.xml file and insert below xml codes:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#drawable/image_background"
>
<ImageView
android:layout_width="20dp"
android:layout_height="20dp"
android:src="#drawable/backspace"
android:layout_above="#+id/view"
android:layout_marginBottom="10dp"
android:layout_alignRight="#+id/view"
android:id="#+id/imageView" />
<View
android:layout_width="200dp"
android:layout_height="1dp"
android:background="#FFF"
android:layout_above="#+id/numericPad"
android:layout_centerHorizontal="true"
android:layout_marginBottom="20dp"
android:id="#+id/view" />
<TableLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/numericPad"
android:layout_width="200dp"
android:layout_height="200dp"
android:layout_marginTop="20dip"
android:layout_marginLeft="5dip"
android:layout_marginRight="5dip"
android:shrinkColumns="*"
android:stretchColumns="*"
android:layout_alignParentBottom="true"
android:layout_centerHorizontal="true"
>
<TableRow
android:id="#+id/tableRow1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
>
<Button
android:id="#+id/button1"
android:layout_width="0dip"
android:layout_weight="1"
android:layout_height="wrap_content"
android:gravity="center"
android:text="1"
android:textSize="25sp"
android:textColor="#ffffff"
android:padding="6dip"
android:layout_margin="3dip"
android:background="#android:color/transparent"
>
</Button>
<Button
android:id="#+id/button2"
android:layout_width="0dip"
android:layout_weight="1"
android:layout_height="wrap_content"
android:gravity="center"
android:text="2"
android:textSize="25sp"
android:textColor="#ffffff"
android:padding="6dip"
android:layout_margin="3dip"
android:background="#android:color/transparent"
>
</Button>
<Button
android:id="#+id/button3"
android:layout_width="0dip"
android:layout_weight="1"
android:layout_height="wrap_content"
android:gravity="center"
android:text="3"
android:textSize="25sp"
android:textColor="#ffffff"
android:padding="6dip"
android:layout_margin="3dip"
android:background="#android:color/transparent"
>
</Button>
</TableRow>
<TableRow
android:id="#+id/tableRow2"
android:layout_width="match_parent"
android:layout_height="wrap_content"
>
<Button
android:id="#+id/button4"
android:layout_width="0dip"
android:layout_weight="1"
android:layout_height="wrap_content"
android:gravity="center"
android:text="4"
android:textSize="25sp"
android:textColor="#ffffff"
android:padding="6dip"
android:layout_margin="3dip"
android:background="#android:color/transparent"
>
</Button>
<Button
android:id="#+id/button5"
android:layout_width="0dip"
android:layout_weight="1"
android:layout_height="wrap_content"
android:gravity="center"
android:text="5"
android:textSize="25sp"
android:textColor="#ffffff"
android:padding="6dip"
android:layout_margin="3dip"
android:background="#android:color/transparent"
>
</Button>
<Button
android:id="#+id/button6"
android:layout_width="0dip"
android:layout_weight="1"
android:layout_height="wrap_content"
android:gravity="center"
android:text="6"
android:textSize="25sp"
android:textColor="#ffffff"
android:padding="6dip"
android:layout_margin="3dip"
android:background="#android:color/transparent"
>
</Button>
</TableRow>
<TableRow
android:id="#+id/tableRow3"
android:layout_width="match_parent"
android:layout_height="wrap_content"
>
<Button
android:id="#+id/button7"
android:layout_width="0dip"
android:layout_weight="1"
android:layout_height="wrap_content"
android:gravity="center"
android:text="7"
android:textSize="25sp"
android:textColor="#ffffff"
android:padding="6dip"
android:layout_margin="3dip"
android:background="#android:color/transparent"
>
</Button>
<Button
android:id="#+id/button8"
android:layout_width="0dip"
android:layout_weight="1"
android:layout_height="wrap_content"
android:gravity="center"
android:text="8"
android:textSize="25sp"
android:textColor="#ffffff"
android:padding="6dip"
android:layout_margin="3dip"
android:background="#android:color/transparent"
>
</Button>
<Button
android:id="#+id/button9"
android:layout_width="0dip"
android:layout_weight="1"
android:layout_height="wrap_content"
android:gravity="center"
android:text="9"
android:textSize="25sp"
android:textColor="#ffffff"
android:padding="6dip"
android:layout_margin="3dip"
android:background="#android:color/transparent"
>
</Button>
</TableRow>
<TableRow
android:id="#+id/tableRow4"
android:layout_width="match_parent"
android:layout_height="wrap_content"
>
<Button
android:id="#+id/buttonExit"
android:layout_width="0dip"
android:layout_weight="1"
android:layout_height="wrap_content"
android:gravity="center"
android:text="Exit"
android:textSize="25sp"
android:textColor="#ffffff"
android:padding="6dip"
android:layout_margin="3dip"
android:background="#android:color/transparent"
>
</Button>
<Button
android:id="#+id/button0"
android:layout_width="0dip"
android:layout_weight="1"
android:layout_height="wrap_content"
android:gravity="center"
android:text="0"
android:textSize="25sp"
android:textColor="#ffffff"
android:padding="6dip"
android:layout_margin="3dip"
android:background="#android:color/transparent"
>
</Button>
<Button
android:id="#+id/buttonDeleteBack"
android:layout_width="0dip"
android:layout_weight="1"
android:layout_height="wrap_content"
android:gravity="center"
android:text="Delete"
android:textSize="25sp"
android:textColor="#ffffff"
android:padding="6dip"
android:layout_margin="3dip"
android:background="#android:color/transparent"
>
</Button>
</TableRow>
<TableRow
android:layout_width="fill_parent"
android:layout_height="fill_parent"></TableRow>
<TableRow
android:layout_width="fill_parent"
android:layout_height="fill_parent"></TableRow>
<TableRow
android:layout_width="fill_parent"
android:layout_height="fill_parent"></TableRow>
<TableRow
android:layout_width="fill_parent"
android:layout_height="fill_parent"></TableRow>
<TableRow
android:layout_width="fill_parent"
android:layout_height="fill_parent"></TableRow>
<TableRow
android:layout_width="fill_parent"
android:layout_height="fill_parent"></TableRow>
<TableRow
android:layout_width="fill_parent"
android:layout_height="fill_parent"></TableRow>
<TableRow
android:layout_width="fill_parent"
android:layout_height="fill_parent"></TableRow>
<TableRow
android:layout_width="fill_parent"
android:layout_height="fill_parent">
</TableRow>
</TableLayout>
<EditText
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:inputType="textPassword"
android:ems="10"
android:id="#+id/editText"
android:layout_alignBottom="#+id/imageView"
android:layout_centerHorizontal="true"
android:background="#android:color/transparent"
/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceMedium"
android:text="Enter Password"
android:id="#+id/statusview"
android:layout_below="#+id/time"
android:layout_centerHorizontal="true" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceLarge"
android:text="23:17"
android:id="#+id/time"
android:textSize="100sp"
android:layout_marginTop="64dp"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true" />
note : userPin variable is your password and you can change it.
in below bock in activity class you should insert your code that you want execute if user enter correnct password (e.g start a new activity )
if (userEntered.equals(userPin))
{
statusView.setTextColor(Color.GREEN);
statusView.setText("Correct");
Log.v("PinView", "Correct PIN");
finish();
}
Note: add below line to main activity node in mainfist.xml file
android:theme="#android:style/Theme.NoTitleBar"
so your Activity node must be like :
<activity
android:name="com.example.MainActivity"
android:theme="#android:style/Theme.NoTitleBar"
>
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>

Issue with Android Check Box Visibility?

In my application I have two Check boxes one is PayByCredit and one more is PaybySMS For Both the check boxes are not visible what was the issue ? To display the Check box i gave code like this android:visibility="visible" but still no use . Can any one help me out of this please ?
My XML Code is :
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#drawable/homescreeen2"
android:orientation="vertical" >
<RelativeLayout
android:id="#+id/toplayout"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentTop="true" >
<TextView
android:id="#+id/textView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_centerVertical="true"
android:fontFamily="Optima"
android:gravity="center"
android:text="#string/palmtreeimg"
android:textColor="#ffffff"
android:textStyle="bold" />
<ImageButton
android:id="#+id/imageButton1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_marginLeft="16dp"
android:layout_marginTop="4dp"
android:background="#null"
android:contentDescription="#string/backbt"
android:src="#drawable/backbt" />
</RelativeLayout>
<ScrollView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_below="#+id/toplayout"
android:paddingBottom="10dp"
android:scrollbars="none" >
<RelativeLayout
android:id="#+id/mainlayout"
android:layout_width="match_parent"
android:layout_height="wrap_content" >
<TextView
android:id="#+id/textView3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_margin="15dp"
android:layout_marginLeft="10dp"
android:fontFamily="#+fonts/MontereyFLF"
android:text="#string/realname"
android:textColor="#ff0000" />
<LinearLayout
android:id="#+id/mainlayout2"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_below="#+id/textView3"
android:layout_margin="15dp"
android:background="#drawable/layout_bg"
android:orientation="vertical"
android:paddingBottom="5dp" >
<LinearLayout
android:id="#+id/getaplague"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_margin="10dp"
android:orientation="horizontal" >
<include
android:id="#+id/cmpndbtnName"
android:layout_gravity="center"
android:layout_margin="10dp"
android:layout_marginStart="#+id/treesplanted"
layout="#layout/compound_button" />
</LinearLayout>
<View
android:id="#+id/border"
android:layout_width="fill_parent"
android:layout_height="0.5dp"
android:layout_marginLeft="2dp"
android:layout_marginRight="2dp"
android:background="#a79a88"
android:visibility="gone" />
<LinearLayout
android:id="#+id/entername"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_margin="15dp"
android:alpha="0.8"
android:orientation="horizontal"
android:visibility="gone" >
<TextView
android:id="#+id/name"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/name"
android:textColor="#ff0000" />
</LinearLayout>
<ImageButton
android:id="#+id/imageButton3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_marginLeft="5dp"
android:background="#null"
android:contentDescription="#string/btn_save"
android:src="#drawable/savesmall"
android:visibility="gone" />
</LinearLayout>
<LinearLayout
android:id="#+id/linearLayout1"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_below="#+id/mainlayout2"
android:layout_margin="15dp"
android:background="#drawable/layout_bg"
android:orientation="vertical" >
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_margin="10dp"
android:orientation="horizontal" >
<include
android:id="#+id/cmpndbtnfrnname"
android:layout_marginStart="#+id/treesplanted"
layout="#layout/compound_buttonfrnname" />
</LinearLayout>
<View
android:layout_width="fill_parent"
android:layout_height="0.5dp"
android:layout_marginLeft="2dp"
android:layout_marginRight="2dp"
android:background="#a79a88" />
<LinearLayout
android:id="#+id/enterfrnname"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_margin="15dp"
android:alpha="0.8"
android:orientation="horizontal"
android:visibility="gone" >
</LinearLayout>
<View
android:layout_width="fill_parent"
android:layout_height="0.5dp"
android:layout_marginLeft="2dp"
android:layout_marginRight="2dp"
android:background="#a79a88" />
<LinearLayout
android:id="#+id/enterfrnmailid"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_margin="15dp"
android:orientation="horizontal"
android:visibility="gone" >
<EditText
android:id="#+id/editTextfrnmail"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginLeft="5dp"
android:layout_weight="1"
android:background="#null"
android:hint="#string/enterfrnmailid"
android:inputType="text"
android:textSize="12sp"
android:paddingLeft="5dp"
android:textColor="#000000"
android:textColorHint="#999898" >
</EditText>
</LinearLayout>
<View
android:layout_width="fill_parent"
android:layout_height="0.5dp"
android:layout_marginLeft="2dp"
android:layout_marginRight="2dp"
android:background="#a79a88" />
<LinearLayout
android:id="#+id/enterfrnphoneno"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_margin="15dp"
android:orientation="horizontal"
android:visibility="gone" >
</EditText>
</LinearLayout>
</LinearLayout>
<View
android:layout_width="fill_parent"
android:layout_height="0.5dp"
android:layout_marginLeft="2dp"
android:layout_marginRight="2dp"
android:background="#a79a88" />
<View
android:layout_width="fill_parent"
android:layout_height="0.5dp"
android:layout_marginLeft="2dp"
android:layout_marginRight="2dp"
android:background="#a79a88" />
<LinearLayout
android:id="#+id/linearLayout2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#+id/linearLayout1"
android:layout_margin="15dp"
android:layout="#+id/amntlayout"
android:orientation="horizontal" >
</LinearLayout>
<LinearLayout
android:id="#+id/mainlayoutpay"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_below="#+id/linearLayout2"
android:layout_margin="15dp"
android:background="#drawable/layout_bg"
android:orientation="vertical"
android:paddingBottom="5dp" >
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_margin="10dp"
android:orientation="horizontal" >
<TextView
android:id="#+id/txpaycredit"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_margin="10dp"
android:fontFamily="Optima"
android:text="#string/paycredit"
android:textColor="#ff0000" />
<TextView
android:id="#+id/dum"
android:layout_width="40dp"
android:layout_height="wrap_content"
android:layout_margin="10dp"
android:fontFamily="Optima"
android:text=""
/>
<CheckBox
android:id="#+id/paycredit"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_margin="10dp"
android:background="#null"
android:visibility="visible"
android:textColor="#000000" />
</LinearLayout>
<View
android:layout_width="fill_parent"
android:layout_height="0.5dp"
android:layout_marginLeft="2dp"
android:layout_marginRight="2dp"
android:background="#a79a88" />
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_margin="10dp"
android:layout_marginTop="0dp"
android:orientation="horizontal" >
<TextView
android:id="#+id/paybysms"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_margin="10dp"
android:text="#string/paysms"
android:textColor="#ff0000" />
<TextView
android:id="#+id/dummy"
android:layout_width="70dp"
android:layout_height="wrap_content"
android:layout_margin="10dp"
android:text=""
android:textColor="#ff0000" />
<CheckBox
android:id="#+id/paysms"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_margin="16dp"
android:background="#null"
android:visibility="visible"
android:layout_marginLeft="10dp"
android:fontFamily="#+fonts/MontereyFLF"
android:textColor="#000000" />
</LinearLayout>
</LinearLayout>
</RelativeLayout>
</ScrollView>
</RelativeLayout>
And My .java Code is here:
import android.widget.CheckBox;
import android.widget.CompoundButton;
import android.widget.CompoundButton.OnCheckedChangeListener;
import android.widget.EditText;
import android.widget.ImageButton;
import android.widget.LinearLayout;
import android.widget.TextView;
import android.widget.Toast;
import com.paypal.android.sdk.payments.PayPalConfiguration;
import com.paypal.android.sdk.payments.PayPalPayment;
import com.paypal.android.sdk.payments.PayPalService;
import com.paypal.android.sdk.payments.PaymentActivity;
import com.paypal.android.sdk.payments.PaymentConfirmation;
public class PalmTreeActivity extends Activity {
//Used for payment
double currencyAftconversion;
public String treeValue;
private static final String CONFIG_ENVIRONMENT = PayPalConfiguration.ENVIRONMENT_NO_NETWORK;
private static final String CONFIG_CLIENT_ID = "AWg-FRC9GM1CdolC2XnKnYBEgpi01jDlKi6IEXFcEnu4QIfer6cVE0iH9YNI";
private static PayPalConfiguration config = new PayPalConfiguration()
.environment(CONFIG_ENVIRONMENT)
.clientId(CONFIG_CLIENT_ID)
.merchantName("Isaaf")
.merchantPrivacyPolicyUri(
Uri.parse("https://www.example.com/privacy"))
.merchantUserAgreementUri(
Uri.parse("https://www.example.com/legal"));
String AmountOfTree = null;
#Override
protected void onCreate(Bundle savedInstanceState) {
String price = null;
//call currency conversion method
new DownloadCurrencyConversion().execute();
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_palmtree);
ImageButton btnNext = (ImageButton) findViewById(R.id.imageButton2);
ImageButton btBack = (ImageButton) findViewById(R.id.imageButton1);
final CheckBox paybycard = (CheckBox) findViewById(R.id.paycredit);
//paycredit.setVisibility(View.VISIBLE);
final CheckBox paybysms = (CheckBox) findViewById(R.id.paysms);
final CompoundButton switchrealname= (CompoundButton) findViewById(R.id.enabled);
final CompoundButton switchfrnname=(CompoundButton) findViewById(R.id.enabledfrnname);
final LinearLayout friendName=(LinearLayout) findViewById(R.id.enterfrnname);
final LinearLayout friendMailId=(LinearLayout) findViewById(R.id.enterfrnmailid);
final LinearLayout friendPhoneno=(LinearLayout) findViewById(R.id.enterfrnphoneno);
final LinearLayout Name=(LinearLayout) findViewById(R.id.entername);
final EditText username=(EditText)findViewById(R.id.editText1);
final EditText frnName=(EditText)findViewById(R.id.editTextfrnName);
final EditText frnmail=(EditText)findViewById(R.id.editTextfrnmail);
final EditText frnphoneno=(EditText)findViewById(R.id.editTextfrnphoneno);
// final ImageButton savename=(ImageButton)findViewById(R.id.imageButton3);
// final ImageButton savefrnname=(ImageButton) findViewById(R.id.imageButton4);
if (getIntent().getExtras() != null && !TextUtils.isEmpty("price"))
{
price = getIntent().getExtras().getString("price");
TextView amount = (TextView) findViewById(R.id.amountvalue);
amount.setGravity(Gravity.CENTER);
String Pricedouble = price.substring(price.indexOf('('));
Pricedouble = Pricedouble.replaceAll("\\D+", "");
amount.setText(Pricedouble.toString()); // Get Number
//EditText amounttext = (EditText) findViewById(R.id.editText1);
//amounttext.setText(Pricedouble);
AmountOfTree = Pricedouble.toString();
Intent intentActivity = new Intent(this, PayPalService.class);
intentActivity.putExtra(PayPalService.EXTRA_PAYPAL_CONFIGURATION, config);
startService(intentActivity);
}
//button next click
btnNext.setOnClickListener(new OnClickListener() {
#Override
public void onClick(View view) {
if (paybycard.isChecked()) {
Bundle bundle=new Bundle();
if(!TextUtils.isEmpty(username.getText().toString()))
bundle.putString("name", username.getText().toString());
if(!TextUtils.isEmpty(frnName.getText().toString()))
bundle.putString("frnname", frnName.getText().toString());
if(!TextUtils.isEmpty(frnmail.getText().toString()))
bundle.putString("frnmailid", frnmail.getText().toString());
if(!TextUtils.isEmpty(frnphoneno.getText().toString()))
bundle.putString("frnphoneno", frnphoneno.getText().toString());
PayPalPayment payment = new PayPalPayment(new BigDecimal(
currencyAftconversion), "USD", "Tree",
PayPalPayment.PAYMENT_INTENT_SALE);
Intent intent = new Intent(getApplicationContext(),
PaymentActivity.class);
intent.putExtra(PaymentActivity.EXTRA_PAYMENT, payment);
startActivityForResult(intent, 0);
}
else if(paybysms.isChecked())
{
StringBuilder tmp=new StringBuilder();
if(!TextUtils.isEmpty(username.getText().toString()));
tmp.append("User details are :"+"\n");
tmp.append("UserName is:"+username.getText().toString());
tmp.append("\n");
//tmp.append(username.getText().toString());
if(!TextUtils.isEmpty(frnName.getText().toString()))
tmp.append("Friend Name is:"+frnName.getText().toString());
tmp.append("\n");
if(!TextUtils.isEmpty(frnmail.getText().toString()))
tmp.append("Friend Email id is:"+frnmail.getText().toString());
tmp.append("\n");
if(!TextUtils.isEmpty(frnphoneno.getText().toString()))
tmp.append("Friend phone number is:"+frnphoneno.getText().toString());
PayByCash senddetailstoadmin=new PayByCash();
if(!TextUtils.isEmpty(tmp.toString()))
senddetailstoadmin.execute(tmp.toString());
Toast paymessage=Toast.makeText(getApplicationContext(), "Our customer care people will contact you shortly..!!!!", Toast.LENGTH_SHORT);
paymessage.show();
Intent intent=new Intent( getApplicationContext(),PaycashthanksActivity.class);
startActivity(intent);
}
else
{
Toast paywarning=Toast.makeText(getApplicationContext(), "Please pay using card or pay by cash", Toast.LENGTH_SHORT);
paywarning.show();
}
}
});
btBack.setOnClickListener(new OnClickListener() {
public void onClick(View view) {
Intent intent = new Intent(getApplicationContext(),
FindmarkedLocationActivity.class);
startActivity(intent);
}
});
//switchrealname toggle
switchrealname.setOnCheckedChangeListener(new OnCheckedChangeListener()
{
#Override
public void onCheckedChanged(CompoundButton buttonView,
boolean isChecked)
{
if(switchrealname.isChecked())
{
Name.setVisibility(View.VISIBLE); //Set the layout visible
// savename.setVisibility(View.VISIBLE);
}
else
{
Name.setVisibility(View.GONE);
// savename.setVisibility(View.GONE);
}
}
});
//Switch friend details switch toggle checked event
switchfrnname.setOnCheckedChangeListener(new OnCheckedChangeListener()
{
#Override
public void onCheckedChanged(CompoundButton buttonView,
boolean isChecked)
{
if(switchfrnname.isChecked())
{
//Set the layout visible
friendName.setVisibility(View.VISIBLE);
friendMailId.setVisibility(View.VISIBLE);
friendPhoneno.setVisibility(View.VISIBLE);
// savefrnname.setVisibility(View.VISIBLE);
}
else
{
//Set the layout visible
friendName.setVisibility(View.GONE);
friendMailId.setVisibility(View.GONE);
friendPhoneno.setVisibility(View.GONE);
// savefrnname.setVisibility(View.GONE);
}
}
});
}
#Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
if (resultCode == Activity.RESULT_OK) {
PaymentConfirmation confirm = data
.getParcelableExtra(PaymentActivity.EXTRA_RESULT_CONFIRMATION);
if (confirm != null) {
try {
Log.i("paymentExample", confirm.toJSONObject().toString(4));
// TODO: send 'confirm' to your server for verification or
// consent
// completion.
// see
// https://developer.paypal.com/webapps/developer/docs/integration/mobile/verify-mobile-payment/
// for more details.
Intent intent = new Intent(getApplicationContext(),
CongratulationActivity.class);
startActivity(intent);
}
catch (JSONException e)
{
sorryActivity();
Log.e("paymentExample",
"an extremely unlikely failure occurred: ", e);
}
}
} else if (resultCode == Activity.RESULT_CANCELED) {
Log.i("paymentExample", "The user canceled.");
} else if (resultCode == PaymentActivity.RESULT_EXTRAS_INVALID)
{
sorryActivity();
Log.i("paymentExample",
"An invalid Payment was submitted. Please see the docs.");
}
}
//back button click
public String getJson(String url) throws ClientProtocolException,
IOException {
StringBuilder build = new StringBuilder();
HttpClient client = new DefaultHttpClient();
HttpGet httpGet = new HttpGet(url);
HttpResponse response = client.execute(httpGet);
HttpEntity entity = response.getEntity();
InputStream content = entity.getContent();
BufferedReader reader = new BufferedReader(new InputStreamReader(
content));
String con;
while ((con = reader.readLine()) != null) {
build.append(con);
}
return build.toString();
}
public void sorryActivity()
{
Intent intent = new Intent(getApplicationContext(),
SorryPaymentActivity.class);
startActivity(intent);
}
#Override
public void onDestroy() {
stopService(new Intent(this, PayPalService.class));
super.onDestroy();
}
public class DownloadCurrencyConversion extends
AsyncTask<Void, Integer, String> {
#Override
protected String doInBackground(Void... params) {
String s;
String theResult = "";
try {
s = getJson("http://query.yahooapis.com/v1/public/yql?q=select%20*%20from%20yahoo.finance.xchange%20where%20pair%20in%20%28%22BHDUSD%22%29&format=json&env=store%3A%2F%2Fdatatables.org%2Falltableswithkeys&callback=");
JSONObject jObj;
jObj = new JSONObject(s);
theResult = jObj.getJSONObject("query")
.getJSONObject("results").getJSONObject("rate")
.getString("Rate");
System.out.println(theResult);
}
catch (JSONException e) {
e.printStackTrace();
} catch (ClientProtocolException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
return theResult;
}
#Override
protected void onPostExecute(String theResult) {
super.onPostExecute(theResult);
System.out.println("theResult:" + theResult);
if (!TextUtils.isEmpty(theResult) &&!TextUtils.isEmpty(AmountOfTree) )
currencyAftconversion = (Double.parseDouble(AmountOfTree))
* (Double.parseDouble(theResult));
}
}
}
Please help me out of this issue ??
Remove android:background="#null"
In your code try this:
paybycard.setVisibility(0);
paybysms.setVisibility(0);
Hope this help, thanks
These layouts work for me:
<CheckBox
android:id="#+id/paysms"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="16dp"
android:background="#null"
android:visibility="visible"
android:text="pay with sms"
android:layout_marginLeft="10dp"
android:textColor="#000000" />
<CheckBox
android:id="#+id/paycredit"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#id/paysms"
android:background="#null"
android:text="pay credit"
android:visibility="visible"
android:layout_marginLeft="10dp"
android:textColor="#000000" />

An alert dialog with an image will appear once LinearLayout is clicked

Symptoms.java
package com.example.des;
import java.util.ArrayList;
import com.example.des.R;
import com.example.des.Symptoms;
import com.example.des.Learn_Dengue;
import android.os.Bundle;
import android.os.Handler;
import android.app.Activity;
import android.app.AlertDialog;
import android.content.Intent;
import android.view.Gravity;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.CheckBox;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.Toast;
public class Symptoms extends Activity implements OnClickListener{
//set variables
CheckBox q1; CheckBox q2; CheckBox q3; CheckBox q4; CheckBox q5; CheckBox q6;
CheckBox q7; CheckBox q8; CheckBox q9 ;CheckBox q10; CheckBox q11; CheckBox q12;
LinearLayout sas1; LinearLayout sas2; LinearLayout sas3; LinearLayout sas4; LinearLayout sas5; LinearLayout sas6;
LinearLayout sas7; LinearLayout sas8; LinearLayout sas9; LinearLayout sas10; LinearLayout sas11; LinearLayout sas12;
Button btndone;
Button btnlearn;
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.question);
q1 = (CheckBox)findViewById(R.id.q1a); //Question number 1--main symptom
q2 = (CheckBox)findViewById(R.id.q2a);
q3 = (CheckBox)findViewById(R.id.q3a);
q4 = (CheckBox)findViewById(R.id.q4a);
q5 = (CheckBox)findViewById(R.id.q5a);
q6 = (CheckBox)findViewById(R.id.q6a);
q7 = (CheckBox)findViewById(R.id.q7a);
q8 = (CheckBox)findViewById(R.id.q8a);
q9 = (CheckBox)findViewById(R.id.q9a);
q10 = (CheckBox)findViewById(R.id.q10a);
q11 = (CheckBox)findViewById(R.id.q11a);
q12 = (CheckBox)findViewById(R.id.q12a);
sas1 = (LinearLayout)findViewById(R.id.sas1view);
sas2 = (LinearLayout)findViewById(R.id.sas2view);
sas3 = (LinearLayout)findViewById(R.id.sas3view);
sas4 = (LinearLayout)findViewById(R.id.sas4view);
sas5 = (LinearLayout)findViewById(R.id.sas5view);
sas6 = (LinearLayout)findViewById(R.id.sas6view);
sas7 = (LinearLayout)findViewById(R.id.sas7view);
sas8 = (LinearLayout)findViewById(R.id.sas8view);
sas9 = (LinearLayout)findViewById(R.id.sas9view);
sas10 = (LinearLayout)findViewById(R.id.sas10view);
sas11 = (LinearLayout)findViewById(R.id.sas11view);
sas12 = (LinearLayout)findViewById(R.id.sas12view);
btndone = (Button) findViewById(R.id.done);
btndone.setOnClickListener(this);
btnlearn = (Button) findViewById(R.id.learn);
btnlearn.setOnClickListener(this);
}
#Override
public void onClick(View v) {
// When button "Result" is pressed
switch (v.getId()) {
case R.id.done:
ArrayList<CheckBox> cbList = new ArrayList<CheckBox>();
// Array CheckBox 2 - 12 inside an Array (sub symptoms)
cbList.add((CheckBox)findViewById(R.id.q2a));
cbList.add((CheckBox)findViewById(R.id.q3a));
cbList.add((CheckBox)findViewById(R.id.q4a));
cbList.add((CheckBox)findViewById(R.id.q5a));
cbList.add((CheckBox)findViewById(R.id.q6a));
cbList.add((CheckBox)findViewById(R.id.q7a));
cbList.add((CheckBox)findViewById(R.id.q8a));
cbList.add((CheckBox)findViewById(R.id.q9a));
cbList.add((CheckBox)findViewById(R.id.q10a));
cbList.add((CheckBox)findViewById(R.id.q11a));
cbList.add((CheckBox)findViewById(R.id.q12a));
// Starts Looping if CheckBox number 1 is selected and the others (result SUSPICIOUS)
if (q1.isChecked()) {
int count = 0;
for (CheckBox cb : cbList) {
if (cb.isChecked()) {
count++;
}
}
if (count == 2 || count == 1 || count == 0) {
new AlertDialog.Builder(this).setMessage(R.string.suspicious).show();
}
}
// START Looping if CheckBox number 1 is selected but 11 and 12 are not (result MOST LIKELY)
if (q1.isChecked()) {
int count = 0;
for (CheckBox cb : cbList) {
if (cb.isChecked()) {
count++;
}
}
if (count >= 3 && count < 11) {
new AlertDialog.Builder(this).setMessage(R.string.most_likely).show();
}
}
// START Looping if all CheckBox are selected(result POSITIVE)
if (q1.isChecked() && q2.isChecked() && q3.isChecked() && q4.isChecked() &&
q5.isChecked() && q6.isChecked() && q7.isChecked() && q8.isChecked() &&
q9.isChecked() && q10.isChecked() && q11.isChecked() && q12.isChecked()) {
int count = 0;
for (CheckBox cb : cbList) {
if (cb.isChecked()) {
count++;
}
}
if (count == 11) {
new AlertDialog.Builder(this).setMessage(R.string.positive).show();
}
}
// Starts Looping if CheckBox number 1 is not selected and the others are checked
if (!q1.isChecked()) {
int count = 0;
for (CheckBox cb : cbList) {
if (cb.isChecked()) {
count++;
}
}
if (count <= 1 || count > 1) {
//this Toast will show when only 1 or more check box will be checked(excluding check box #1)
/*Toast toast= Toast.makeText(getApplicationContext(), getString(R.string.negative), Toast.LENGTH_LONG);
toast.setGravity(Gravity.CENTER, 0, 0);
toast.show();
*/
new AlertDialog.Builder(this).setMessage(R.string.negative).show();
}
}
break;
// When button "Learn More" is pressed
case R.id.learn:
Intent q = new Intent(this, Learn_Dengue.class);
startActivity(q);
break;
}
Here start my question.
sas1.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View view) {
//Alert Dialog with image
}
});
sas2.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View view) {
//Alert Dialog with image
}
});
sas3.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View view) {
//Alert Dialog with image
}
});
sas4.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View view) {
//Alert Dialog with image
}
});
sas5.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View view) {
//Alert Dialog with image
}
});
sas6.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View view) {
//Alert Dialog with image
}
});
sas7.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View view) {
//Alert Dialog with image
}
});
sas8.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View view) {
//Alert Dialog with image
}
});
sas9.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View view) {
//Alert Dialog with image
}
});
sas10.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View view) {
//Alert Dialog with image
}
});
sas11.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View view) {
//Alert Dialog with image
}
});
sas12.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View view) {
//Alert Dialog with image
}
});
}
}
questions.xml
<?xml version="1.0" encoding="utf-8"?>
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/scrollView1"
style="#style/styleName"
android:layout_width="match_parent"
android:layout_height="wrap_content" >
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical" >
<TextView
android:id="#+id/textView3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/warning"
android:textAppearance="?android:attr/textAppearanceMedium" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content" >
<CheckBox
android:id="#+id/q1a"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
<LinearLayout
android:layout_marginTop="15dp"
android:id="#+id/sas1view"
android:layout_width="match_parent"
android:layout_height="30dp" >
<TextView
android:id="#+id/sas1"
android:layout_width="wrap_content"
android:layout_height="30dp"
android:text="#string/sas1"
android:textAppearance="?android:attr/textAppearanceSmall"
android:textColor="#000000"
android:textSize="15sp"
android:textStyle="bold" />
</LinearLayout>
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content" >
<CheckBox
android:id="#+id/q2a"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
<LinearLayout
android:layout_marginTop="15dp"
android:id="#+id/sas2view"
android:layout_width="match_parent"
android:layout_height="30dp" >
<TextView
android:id="#+id/sas2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/sas2"
android:textAppearance="?android:attr/textAppearanceSmall"
android:textColor="#000000"
android:textSize="15sp"
android:textStyle="bold" />
</LinearLayout>
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content" >
<CheckBox
android:id="#+id/q3a"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
<LinearLayout
android:layout_marginTop="15dp"
android:id="#+id/sas3view"
android:layout_width="match_parent"
android:layout_height="30dp" >
<TextView
android:id="#+id/sas3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/sas3"
android:textAppearance="?android:attr/textAppearanceSmall"
android:textColor="#000000"
android:textSize="15sp"
android:textStyle="bold" />
</LinearLayout>
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content" >
<CheckBox
android:id="#+id/q4a"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
<LinearLayout
android:layout_marginTop="15dp"
android:id="#+id/sas4view"
android:layout_width="match_parent"
android:layout_height="30dp" >
<TextView
android:id="#+id/sas4"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/sas4"
android:textAppearance="?android:attr/textAppearanceSmall"
android:textColor="#000000"
android:textSize="15sp"
android:textStyle="bold" />
</LinearLayout>
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content" >
<CheckBox
android:id="#+id/q5a"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
<LinearLayout
android:layout_marginTop="15dp"
android:id="#+id/sas5view"
android:layout_width="match_parent"
android:layout_height="30dp" >
<TextView
android:id="#+id/sas5"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/sas5"
android:textAppearance="?android:attr/textAppearanceSmall"
android:textColor="#000000"
android:textSize="15sp"
android:textStyle="bold" />
</LinearLayout>
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content" >
<CheckBox
android:id="#+id/q6a"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
<LinearLayout
android:layout_marginTop="15dp"
android:id="#+id/sas6view"
android:layout_width="match_parent"
android:layout_height="30dp" >
<TextView
android:id="#+id/sas6"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/sas6"
android:textAppearance="?android:attr/textAppearanceSmall"
android:textColor="#000000"
android:textSize="15sp"
android:textStyle="bold" />
</LinearLayout>
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content" >
<CheckBox
android:id="#+id/q7a"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
<LinearLayout
android:layout_marginTop="15dp"
android:id="#+id/sas7view"
android:layout_width="match_parent"
android:layout_height="30dp" >
<TextView
android:id="#+id/sas7"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/sas7"
android:textAppearance="?android:attr/textAppearanceSmall"
android:textColor="#000000"
android:textSize="15sp"
android:textStyle="bold" />
</LinearLayout>
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content" >
<CheckBox
android:id="#+id/q8a"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
<LinearLayout
android:layout_marginTop="15dp"
android:id="#+id/sas8view"
android:layout_width="match_parent"
android:layout_height="30dp" >
<TextView
android:id="#+id/sas8"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/sas8"
android:textAppearance="?android:attr/textAppearanceSmall"
android:textColor="#000000"
android:textSize="15sp"
android:textStyle="bold" />
</LinearLayout>
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content" >
<CheckBox
android:id="#+id/q9a"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
<LinearLayout
android:layout_marginTop="15dp"
android:id="#+id/sas9view"
android:layout_width="match_parent"
android:layout_height="30dp" >
<TextView
android:id="#+id/sas9"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/sas9"
android:textAppearance="?android:attr/textAppearanceSmall"
android:textColor="#000000"
android:textSize="15sp"
android:textStyle="bold" />
</LinearLayout>
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content" >
<CheckBox
android:id="#+id/q10a"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
<LinearLayout
android:layout_marginTop="15dp"
android:id="#+id/sas10view"
android:layout_width="match_parent"
android:layout_height="30dp" >
<TextView
android:id="#+id/sas10"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/sas10"
android:textAppearance="?android:attr/textAppearanceSmall"
android:textColor="#000000"
android:textSize="15sp"
android:textStyle="bold" />
</LinearLayout>
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content" >
<CheckBox
android:id="#+id/q11a"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
<LinearLayout
android:layout_marginTop="15dp"
android:id="#+id/sas11view"
android:layout_width="match_parent"
android:layout_height="30dp" >
<TextView
android:id="#+id/sas11"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/sas11"
android:textAppearance="?android:attr/textAppearanceSmall"
android:textColor="#000000"
android:textSize="15sp"
android:textStyle="bold" />
</LinearLayout>
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content" >
<CheckBox
android:id="#+id/q12a"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
<LinearLayout
android:layout_marginTop="15dp"
android:id="#+id/sas12view"
android:layout_width="match_parent"
android:layout_height="30dp" >
<TextView
android:id="#+id/sas12"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/sas12"
android:textAppearance="?android:attr/textAppearanceSmall"
android:textColor="#000000"
android:textSize="15sp"
android:textStyle="bold" />
</LinearLayout>
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="20dp" >
<Button
android:id="#+id/done"
android:layout_width="120dp"
android:layout_height="40dp"
android:layout_marginLeft="35dp"
android:layout_marginTop="20dp"
android:background="#drawable/btn_orange"
android:text="#string/done"
android:textColor="#ffffff"
android:textSize="15sp" />
<Button
android:id="#+id/learn"
android:layout_width="120dp"
android:layout_height="40dp"
android:layout_marginLeft="10dp"
android:layout_marginTop="20dp"
android:background="#drawable/btn_black"
android:text="#string/learn"
android:textColor="#ffffff"
android:textSize="15sp" />
</LinearLayout>
</LinearLayout>
</ScrollView>
here is my full code as you requested #mobie.. the Symptoms.java and the question.xml..dont matter the other code..just on the alert dialog that i asked.
Create Layout Like Below for Dialog Box : dialog.xml
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent" >
<ImageView
android:id="#+id/image"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginRight="5dp" />
<TextView
android:id="#+id/text"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:textColor="#FFF"
android:layout_toRightOf="#+id/image"/>
<Button
android:id="#+id/dialogButtonOK"
android:layout_width="100px"
android:layout_height="wrap_content"
android:text=" Ok "
android:layout_marginTop="5dp"
android:layout_marginRight="5dp"
android:layout_below="#+id/image"
/>
</RelativeLayout>
Then, Where you want to place the Alert, Do like below
final Dialog dialog = new Dialog(context);
dialog.setContentView(R.layout.dialog);
dialog.setTitle("Your Title");
TextView text = (TextView) dialog.findViewById(R.id.text);
text.setText("Text");
ImageView image = (ImageView) dialog.findViewById(R.id.image);
image.setImageResource(R.drawable.ic_launcher);
Button dialogButton = (Button) dialog.findViewById(R.id.dialogButtonOK);
dialogButton.setOnClickListener(new OnClickListener() {
#Override
public void onClick(View v) {
dialog.dismiss();
}
});
dialog.show();

how to store text value for a radiogroup in sqlite database?

i've a radio group radiogoup1 that hat two radiobutton rbtn1, rbtn2. say i want to store Male for rbtn1 and Female for rbtn2 in database. How to do it? I am mentioning the .xml and .java file.
sqlliteexample.xml :
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content" >
<TextView
android:id="#+id/textName"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/name"
android:paddingLeft="5dp"
android:textAppearance="?android:attr/textAppearanceSmall" />
<EditText
android:id="#+id/editName"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:ems="10"
android:inputType="textPersonName" >
<requestFocus />
</EditText>
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content" >
<TextView
android:id="#+id/textAge"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:paddingLeft="5dp"
android:text="#string/age" >
</TextView>
<EditText
android:id="#+id/editAge"
android:layout_width="80dp"
android:layout_height="wrap_content"
android:ems="10"
android:inputType="number" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content" >
<TextView
android:id="#+id/textContcat"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:paddingLeft="5dp"
android:text="#string/contact" />
<EditText
android:id="#+id/editContact"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:ems="10"
android:inputType="textMultiLine" />
</LinearLayout>
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_marginTop="0dp"
android:orientation="horizontal" >
<TextView
android:id="#+id/sLabel"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:gravity="left|center"
android:paddingLeft="5dp"
android:paddingRight="10dp"
android:text="#string/sx" />
<RadioGroup
android:id="#+id/RadioGroup01"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="horizontal" >
<RadioButton
android:id="#+id/malebutton"
android:layout_width="wrap_content"
android:layout_height="17dp"
android:text="#string/mal"
android:textSize="15sp" />
<RadioButton
android:id="#+id/femalebutton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/femal"
android:textSize="15sp" />
</RadioGroup>
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal" >
<Button
android:id="#+id/savebutton"
style="?android:attr/buttonStyleSmall"
android:layout_width="wrap_content"
android:layout_height="32dp"
android:gravity="left|center"
android:text="#string/save"
android:textSize="13sp" />
<Button
android:id="#+id/viewbutton"
style="?android:attr/buttonStyleSmall"
android:layout_width="wrap_content"
android:layout_height="32dp"
android:layout_gravity="center"
android:gravity="center|left"
android:text="#string/view"
android:textSize="13sp" />
</LinearLayout>
SqlLiteExample.java :
public class SqlLiteExample extends Activity implements OnClickListener, OnCheckedChangeListener {
Button sqlUpdate, sqlView;
EditText etName,etAge,etContact;
RadioGroup rdgrp;
RadioButton selectedRadioButton;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.sqlliteexample);
sqlUpdate = (Button) findViewById(R.id.savebutton);
etName = (EditText) findViewById(R.id.editName);
etAge = (EditText) findViewById(R.id.editAge);
etContact = (EditText) findViewById(R.id.editContact);
rdgrp.setOnCheckedChangeListener(this);
sqlView = (Button) findViewById(R.id.viewbutton);
sqlView.setOnClickListener(this);
sqlUpdate.setOnClickListener(this);
}
#Override
public void onClick(View arg0) {
// TODO Auto-generated method stub
switch(arg0.getId()){
case R.id.savebutton:
boolean didWork = true;
try{
String name = etName.getText().toString();
String age = etAge.getText().toString();
String contact = etContact.getText().toString();
MyDB entry = new MyDB(SqlLiteExample.this);
entry.open();
entry.createEntry(name,age,contact);
entry.close();
}catch(Exception e){
didWork = false;
String error = e.toString();
Dialog d = new Dialog(this);
d.setTitle("Error");
TextView tv = new TextView(this);
tv.setText(error);
d.setContentView(tv);
d.show();
}finally{
if(didWork){
Dialog d = new Dialog(this);
d.setTitle("Updated");
TextView tv = new TextView(this);
tv.setText("Success");
d.setContentView(tv);
d.show();
}
}
break;
case R.id.viewbutton:
Intent i = new Intent("com.bysakiralam.mydatabase.DISPLAYRECORDS");
startActivity(i);
break;
}
}
#Override
public void onCheckedChanged(RadioGroup arg0, int arg1) {
// TODO Auto-generated method stub
switch(arg1){
case R.id.malebutton:
break;
case R.id.femalebutton:
break;
}
} }
There is no need to override onCheckedChanged() use following in your on savebutton click
rdgrp=(RadioGroup)findViewById(R.id.RadioGroup01);
String radiovalue= (RadioButton)this.findViewById(rdgrp.getCheckedRadioButtonId())).getText().toString();
and now use radiovalue to store in database
Edit: forget (
rdgrp=(RadioGroup)findViewById(R.id.RadioGroup01);
String radiovalue= ((RadioButton)this.findViewById(rdgrp.getCheckedRadioButtonId())).getText().toString();
try this
myRadioGrp=(RadioGroup)findViewById(R.id.RadioGroup01);
String radiovalue= ((RadioButton)this.findViewById(myRadioGrp.getCheckedRadioButtonId())).getText().toString();

Trying to generate a simple pop-up

I am trying to generate a simple popup on click of a button, but due to some reason it is not working. Below is my code:
public class Product extends Activity {
#Override
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
this.requestWindowFeature(Window.FEATURE_NO_TITLE);
//overridePendingTransition(R.anim.fadein, R.anim.fadeout);
setContentView(R.layout.product);
String fontPath = "fonts/georgia.ttf";
Typeface tf = Typeface.createFromAsset(getAssets(), fontPath);
final Animation animScale = AnimationUtils.loadAnimation(this, R.anim.anim_scale);
Button Particle =(Button)findViewById(R.id.button1);
Button MDF=(Button)findViewById(R.id.button2);
Button Laminates=(Button)findViewById(R.id.button3);
Button Ply =(Button)findViewById(R.id.button4);
Button Floor=(Button)findViewById(R.id.button5);
Button Door=(Button)findViewById(R.id.button6);
Button EdgeBand=(Button)findViewById(R.id.button7);
Button ModFur=(Button)findViewById(R.id.button8);
Particle.setTypeface(tf);
MDF.setTypeface(tf);
Laminates.setTypeface(tf);
Ply.setTypeface(tf);
Floor.setTypeface(tf);
Door.setTypeface(tf);
EdgeBand.setTypeface(tf);
ModFur.setTypeface(tf);
/* Particle.startAnimation(animScale);
MDF.startAnimation(animScale);
Laminates.startAnimation(animScale);
Ply.startAnimation(animScale);
Floor.startAnimation(animScale);
Door.startAnimation(animScale);
EdgeBand.startAnimation(animScale);
ModFur.startAnimation(animScale); */
Particle.setOnClickListener(Par);
}
private View.OnClickListener Par = new View.OnClickListener(){
public void onClick(View v){
openNewDialog();
}
};
private void openNewDialog() {
new AlertDialog.Builder(this).setItems(R.array.pop,new DialogInterface.OnClickListener(){
public void onClick(DialogInterface dialoginterface,int i){
if(i==0){
Intent about = new Intent(Product.this,AboutUs.class);
startActivity(about);
}
if(i==1){
Intent about = new Intent(Product.this,AboutUs.class);
startActivity(about);
}
}});
}
In the Strings.xml file:
<array name="pop">
<item name="easy_label">Key Features</item>
<item name="medium_label">Advantages</item>
</array>
The layout file for the said activity in xml:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="#drawable/universalbg"
android:orientation="vertical" >
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="vertical" >
<TextView
android:id="#+id/textView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true"
android:layout_marginTop="90dp"
android:text="#string/btn2"
android:textColor="#FFFFFF"
android:textSize="24dp"
android:textStyle="bold" />
</RelativeLayout>
<ScrollView
android:layout_marginTop="10dip"
android:layout_marginBottom="03dip"
android:id="#+id/Scroll"
android:layout_height="wrap_content"
android:layout_width="fill_parent" >
<Button
android:id="#+id/button2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignLeft="#+id/button1"
android:layout_below="#+id/button1"
android:layout_marginTop="20dp"
android:background="#drawable/insidebut"
android:text="#string/BTn2"
android:textColor="#900606" />
<Button
android:id="#+id/button3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignLeft="#+id/button2"
android:layout_below="#+id/button2"
android:layout_marginTop="20dp"
android:background="#drawable/insidebut"
android:text="#string/BTn3"
android:textColor="#900606" />
<Button
android:id="#+id/button4"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignLeft="#+id/button3"
android:layout_below="#+id/button3"
android:layout_marginTop="20dp"
android:background="#drawable/insidebut"
android:text="#string/BTn4"
android:textColor="#900606" />
<Button
android:id="#+id/button5"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignLeft="#+id/button4"
android:layout_below="#+id/button4"
android:layout_marginTop="20dp"
android:background="#drawable/insidebut"
android:text="#string/BTn5"
android:textColor="#900606" />
<Button
android:id="#+id/button6"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignLeft="#+id/button5"
android:layout_below="#+id/button5"
android:layout_marginTop="20dp"
android:background="#drawable/insidebut"
android:text="#string/BTn6"
android:textColor="#900606" />
<Button
android:id="#+id/button7"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignLeft="#+id/button6"
android:layout_below="#+id/button6"
android:layout_marginTop="20dp"
android:background="#drawable/insidebut"
android:text="#string/BTn7"
android:textColor="#900606" />
<Button
android:id="#+id/button8"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignLeft="#+id/button7"
android:layout_below="#+id/button7"
android:layout_marginTop="20dp"
android:background="#drawable/insidebut"
android:text="#string/BTn8"
android:textColor="#900606" />
</ScrollView>
You need to call show() in order to actually display the dialog.
private void openNewDialog() {
new AlertDialog.Builder(this).setItems(R.array.pop,new DialogInterface.OnClickListener(){
public void onClick(DialogInterface dialoginterface,int i){
if(i==0){
Intent about = new Intent(Product.this,AboutUs.class);
startActivity(about);
}
if(i==1){
Intent about = new Intent(Product.this,AboutUs.class);
startActivity(about);
}
}}).show(); // Here
}

Categories

Resources