Default pin lock screen layout - android

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>

Related

Buttons Overlap

I made a stopwatch using chronometer with four buttons but when i use the visibility modes to make stop and pause button appear they overlap.... Pls explain why...Below is the code.....
Assume the layout file with buttons in relative layout...
public class StopWatchFragment extends Fragment {
Chronometer chronometer;
Button startStopWatch;
Button stopStopWatch;
Button resetStopWatch;
Button pauseStopWatch;
Button resumeStopWatch;
private long lastPause;
//RelativeLayout relativeLayout;
private int check = 0;
public StopWatchFragment() {
// Required empty public constructor
}
#Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
View rootView = inflater.inflate(R.layout.stopwatch_layout,container,false);
chronometer = (Chronometer) rootView.findViewById(R.id.stopwatch);
startStopWatch = (Button) rootView.findViewById(R.id.startStopWatch);
stopStopWatch = (Button) rootView.findViewById(R.id.stopStopWatch);
resetStopWatch = (Button) rootView.findViewById(R.id.resetStopWatch);
pauseStopWatch = (Button) rootView.findViewById(R.id.pauseStopWatch);
resumeStopWatch = (Button) rootView.findViewById(R.id.resumeStopWatch);
relativeLayout = (RelativeLayout) rootView.findViewById(R.id.parentRelativeLayout);
pauseStopWatch.setVisibility(View.GONE);
//final RelativeLayout.LayoutParams params = new RelativeLayout.LayoutParams(relativeLayout.getLayoutParams());
startStopWatch.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
chronometer.setBase(SystemClock.elapsedRealtime());
chronometer.start();
startStopWatch.setVisibility(View.GONE);
pauseStopWatch.setVisibility(View.VISIBLE);
if(check == 1){
resumeStopWatch.setClickable(true);
}
else{
resumeStopWatch.setClickable(false);
}
//params.setMargins(16,16,16,16);
//pauseStopWatch.setLayoutParams(params);
}
});
pauseStopWatch.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
check = 1;
lastPause = SystemClock.elapsedRealtime();
chronometer.stop();
}
});
resumeStopWatch.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
chronometer.setBase(chronometer.getBase() + SystemClock.elapsedRealtime() - lastPause);
chronometer.start();
resumeStopWatch.setClickable(false);
}
});
stopStopWatch.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
chronometer.stop();
startStopWatch.setVisibility(View.VISIBLE);
pauseStopWatch.setVisibility(View.GONE);
resumeStopWatch.setClickable(false);
}
});
resetStopWatch.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
chronometer.setBase(SystemClock.elapsedRealtime());
chronometer.stop();
resumeStopWatch.setClickable(false);
startStopWatch.setVisibility(View.VISIBLE);
pauseStopWatch.setVisibility(View.GONE);
}
});
return rootView;
}
}
This is the layout file pls refer for this....
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:id="#+id/parentRelativeLayout"
android:layout_height="match_parent"
android:padding="#dimen/activity_horizontal_margin">
<Chronometer
android:layout_centerInParent="true"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textSize="30sp"
android:textAlignment="center"
android:id="#+id/stopwatch"
android:layout_margin="16dp"/>
<ScrollView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#id/stopwatch">
<RelativeLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content">
<Button
android:id="#+id/startStopWatch"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Start"
android:background="#drawable/buttonshape"
android:textSize="24sp" />
<Button
android:id="#+id/pauseStopWatch"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Pause"
android:background="#drawable/buttonshape"
android:textSize="24sp" />
<Button
android:id="#+id/stopStopWatch"
android:layout_marginTop="16dp"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#id/startStopWatch"
android:background="#drawable/buttonshape"
android:text="Stop"
android:textSize="24sp"/>
<Button
android:id="#+id/resetStopWatch"
android:layout_alignParentRight="true"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="#drawable/buttonshape"
android:text="Reset"
android:textSize="24sp" />
<Button
android:id="#+id/resumeStopWatch"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="#drawable/buttonshape"
android:text="Resume"
android:textSize="24sp"
android:layout_marginTop="16dp"
android:layout_alignParentRight="true"
android:layout_below="#id/resetStopWatch"/>
</RelativeLayout>
</ScrollView>
</RelativeLayout>
This is the way buttons work when click on start button
You are hiding the button, but you are still listening with the OnClickListener. Try adding:
pauseStopWatch.setOnClickListener(null);
Then, when you make your button visible:
pauseStopWatch.setOnClickListener(whatever);
Try this layout
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:id="#+id/parentRelativeLayout"
android:layout_height="match_parent"
android:padding="#dimen/activity_horizontal_margin">
<Chronometer
android:layout_centerInParent="true"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textSize="30sp"
android:textAlignment="center"
android:id="#+id/stopwatch"
android:layout_margin="16dp"/>
<ScrollView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="#id/stopwatch">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
>
<LinearLayout
android:gravity="center"
android:layout_width="0dp"
android:layout_weight="1"
android:layout_height="wrap_content"
android:orientation="vertical"
>
<Button
android:id="#+id/startStopWatch"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Start"
android:background="#drawable/buttonshape"
android:textSize="24sp" />
<Button
android:visibility="gone"
android:id="#+id/pauseStopWatch"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Pause"
android:background="#drawable/buttonshape"
android:textSize="24sp" />
<Button
android:id="#+id/stopStopWatch"
android:layout_marginTop="16dp"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#id/startStopWatch"
android:background="#drawable/buttonshape"
android:text="Stop"
android:textSize="24sp"/>
</LinearLayout>
<LinearLayout
android:gravity="center"
android:layout_width="0dp"
android:layout_weight="1"
android:layout_height="wrap_content"
android:orientation="vertical"
>
<Button
android:id="#+id/resetStopWatch"
android:layout_alignParentRight="true"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="#drawable/buttonshape"
android:text="Reset"
android:textSize="24sp" />
<Button
android:id="#+id/resumeStopWatch"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="#drawable/buttonshape"
android:text="Resume"
android:textSize="24sp"
android:layout_marginTop="16dp"
android:layout_alignParentRight="true"
android:layout_below="#id/resetStopWatch"/>
</LinearLayout>
</LinearLayout>
In the above, the pause button will be set to Gone. You make it visible later when user clicks start button

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
}

half or quarter black screen in android

I have an android activity that when I launch sometimes (about 1 in 4 times) it only draws quarter or half the screen before showing it. When I change the orientation or press a button the screen draws properly.
I'm just using TextViews, Buttons, Fonts - no drawing or anything like that.
All of my code for initialising is in the onCreate(). In this method I'm loading a text file, of about 40 lines long, and also getting a shared preference. Could this cause a delay so that it can't draw the intent?
Thanks in advance if anyone has seen anything similar.
EDIT - I tried commenting out the loading of the word list, but it didn't fix the problem.
EDIT 2 - I didn't manage to resolve the problem, but managed to improve it by adding a timer right at the end of the onCreate. I set a low refresh rate and in the tick changed the text of one of the controls. This then seemed to redraw the screen and get rid of the black portions of the screen.
Here is the activity
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/mainRelativeLayout"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="#drawable/blue_abstract_background" >
<RelativeLayout
android:id="#+id/relativeScore"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:gravity="center_horizontal" >
<TextView
android:id="#+id/ScoreLabel"
style="#style/yellowShadowText"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_centerVertical="true"
android:padding="10dip"
android:text="SCORE:"
android:textSize="18dp" />
/>
<TextView
android:id="#+id/ScoreText"
style="#style/yellowShadowText"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerVertical="true"
android:layout_toRightOf="#id/ScoreLabel"
android:padding="5dip"
android:text="0"
android:textSize="18dp" />
<TextView
android:id="#+id/GameTimerText"
style="#style/yellowShadowText"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_centerVertical="true"
android:layout_marginLeft="5dp"
android:layout_marginRight="5dp"
android:minWidth="25dp"
android:text="0"
android:textSize="18dp" />
<TextView
android:id="#+id/GameTimerLabel"
style="#style/yellowShadowText"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerVertical="true"
android:layout_toLeftOf="#id/GameTimerText"
android:padding="10dip"
android:text="TIMER:"
android:textSize="18dp" />
/>
</RelativeLayout>
<RelativeLayout
android:id="#+id/relativeHighScore"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_below="#id/relativeScore" >
<TextView
android:id="#+id/HighScoreLabel"
style="#style/yellowShadowText"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:padding="10dip"
android:text="HIGH SCORE:"
android:textSize="16dp" />
<TextView
android:id="#+id/HighScoreText"
style="#style/yellowShadowText"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_toRightOf="#id/HighScoreLabel"
android:padding="10dip"
android:text="0"
android:textSize="16dp" />
</RelativeLayout>
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_alignParentLeft="true"
android:layout_below="#+id/relativeHighScore"
android:orientation="vertical" >
<LinearLayout
android:id="#+id/linearMissing"
android:layout_width="fill_parent"
android:layout_height="80dp"
android:layout_gravity="center"
android:orientation="vertical" >
<View
android:layout_width="match_parent"
android:layout_height="2dp"
android:background="#color/yellow_text" />
<TextView
android:id="#+id/MissingWordText"
style="#style/yellowShadowText"
android:layout_width="wrap_content"
android:layout_height="fill_parent"
android:layout_gravity="center_horizontal"
android:layout_marginTop="25dp"
android:text="MSSNG WRD"
android:textSize="22dp"
android:typeface="normal" />
</LinearLayout>
<View
android:layout_width="match_parent"
android:layout_height="2dp"
android:background="#color/yellow_text" />
<TableLayout
android:id="#+id/buttonsTableLayout"
android:layout_width="fill_parent"
android:layout_height="wrap_content" >
<TableRow
android:id="#+id/tableRow3"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:gravity="center_horizontal"
android:paddingTop="5dp" >
<Button
android:id="#+id/aVowelButton"
android:layout_width="66dp"
android:layout_height="66dp"
android:layout_gravity="center_horizontal"
android:layout_marginBottom="10dp"
android:layout_marginRight="5dp"
android:background="#drawable/blue_vowel_button"
android:text="#string/a"
android:textColor="#color/yellow_text"
android:textSize="30dp" />
<Button
android:id="#+id/eVowelButton"
android:layout_width="66dp"
android:layout_height="66dp"
android:layout_gravity="center_horizontal"
android:layout_marginBottom="10dp"
android:layout_marginRight="5dp"
android:background="#drawable/blue_vowel_button"
android:text="#string/e"
android:textColor="#color/yellow_text"
android:textSize="30dp" />
</TableRow>
<TableRow
android:id="#+id/tableRow4"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:gravity="center_horizontal" >
<Button
android:id="#+id/iVowelButton"
android:layout_width="66dp"
android:layout_height="66dp"
android:layout_gravity="center_horizontal"
android:layout_margin="5dp"
android:background="#drawable/blue_vowel_buttoni"
android:text="#string/i"
android:textColor="#color/yellow_text"
android:textSize="30dp" />
<Button
android:id="#+id/oVowelButton"
android:layout_width="66dp"
android:layout_height="66dp"
android:layout_gravity="center_horizontal"
android:layout_margin="5dp"
android:background="#drawable/blue_vowel_button"
android:text="#string/o"
android:textColor="#color/yellow_text"
android:textSize="30dp" />
<Button
android:id="#+id/uVowelButton"
android:layout_width="66dp"
android:layout_height="66dp"
android:layout_gravity="center_horizontal"
android:layout_margin="5dp"
android:background="#drawable/blue_vowel_button"
android:text="#string/u"
android:textColor="#color/yellow_text"
android:textSize="30dp" />
</TableRow>
</TableLayout>
<TextView
android:id="#+id/TimeToStartText"
style="#style/yellowShadowText"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:textSize="24dp" />
<Button
android:id="#+id/startButton"
style="#style/yellowShadowText"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:layout_marginTop="10dp"
android:background="#drawable/blue_button_menu"
android:gravity="center"
android:padding="10dip"
android:text="START!"
android:textSize="28dp" />
</LinearLayout>
</RelativeLayout>
And the OnCreate() and a few methods:
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_game);
isNewWord = true;
m_gameScore = 0;
m_category = getCategoryFromExtras();
// loadWordList(m_category);
initialiseTextViewField();
loadHighScoreAndDifficulty();
setFonts();
setButtons();
setStartButton();
enableDisableButtons(false);
}
private void loadHighScoreAndDifficulty() {
//setting preferences
SharedPreferences prefs = this.getSharedPreferences(m_category, Context.MODE_PRIVATE);
int score = prefs.getInt(m_category, 0); //0 is the default value
m_highScore = score;
m_highScoreText.setText(String.valueOf(m_highScore));
prefs = this.getSharedPreferences(DIFFICULTY, Context.MODE_PRIVATE);
m_difficulty = prefs.getString(DIFFICULTY, NRML_DIFFICULTY);
}
private void initialiseTextViewField() {
m_startButton = (Button) findViewById(R.id.startButton);
m_missingWordText = (TextView) findViewById(R.id.MissingWordText);
m_gameScoreText = (TextView) findViewById(R.id.ScoreText);
m_gameScoreLabel = (TextView) findViewById(R.id.ScoreLabel);
m_gameTimerText = (TextView) findViewById(R.id.GameTimerText);
m_gameTimerLabel = (TextView) findViewById(R.id.GameTimerLabel);
m_timeToStartText = (TextView) findViewById(R.id.TimeToStartText);
m_highScoreLabel = (TextView) findViewById(R.id.HighScoreLabel);
m_highScoreText = (TextView) findViewById(R.id.HighScoreText);
}
private String getCategoryFromExtras() {
String category = "";
Bundle extras = getIntent().getExtras();
if (extras != null) {
category = extras.getString("category");
}
return category;
}
private void enableDisableButtons(boolean enable) {
Button button = (Button) findViewById(R.id.aVowelButton);
button.setEnabled(enable);
button = (Button) findViewById(R.id.eVowelButton);
button.setEnabled(enable);
button = (Button) findViewById(R.id.iVowelButton);
button.setEnabled(enable);
button = (Button) findViewById(R.id.oVowelButton);
button.setEnabled(enable);
button = (Button) findViewById(R.id.uVowelButton);
button.setEnabled(enable);
}
private void setStartButton() {
m_startButton.setOnClickListener(new View.OnClickListener() {
public void onClick(View view) {
m_gameScore = 0;
updateScore();
m_startButton.setVisibility(View.GONE);
m_timeToStartText.setVisibility(View.VISIBLE);
startPreTimer();
}
});
}

Categories

Resources