cannot resolve MainActivityBinding and also binding related issues - android

I want to make a scientific calculator.
I found some useful code on this site: http://www.androidauthority.com/build-a-calculator-app-721910/
Then i modified it for my purpose.
In this code i found binding method was used so i made the following changes in my IDE as per the instructions on this site: https://developer.android.com/topic/libraries/data-binding/index.html
i made changes in the build.gradle(module app)
and made changes in my MainActivity.java code also.
but the following error occurred:
MainActivity.java
package com.example.anant.scientificcalculator;
import android.databinding.DataBindingUtil;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import static java.lang.Math.*;
import java.text.DecimalFormat;
//import com.example.anant.scientificcalculator.databinding.MainActivityBinding;
//import android.content.DialogInterface;
//import android.text.TextUtils;
//import android.view.View;
//import android.widget.Button;
//import android.widget.EditText;
//import android.widget.TextView;
public class MainActivity extends AppCompatActivity {
private MainActivityBinding binding; //error in this line cannot resolve MainActivityBinding.
private static final char FACT = '!';
private static final char POWER = '^';
private static final String SQRT = "SQRT";
private static final String SIN = "SIN";
private static final String COS = "COS";
private static final String TAN = "TAN";
private static final String LOG = "LOG";
private static final char LEFTC = '(';
private static final char RIGHTC = ')';
private static final String EXP = "EXP";
private static final String PIE = "PIE";
private static final char ADD = '+';
private static final char SUBTRACT = '-';
private static final char MULTIPlY = '*';
private static final char DIVIDE = '/';
private char CURRENT_ACTION;
private String ADVANCE_ACTION;
private double valueOne = Double.NaN;
private double valueTwo;
private DecimalFormat decimalFormat;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
decimalFormat = new DecimalFormat("#.##########");
MainActivityBinding binding = DataBindingUtil.setContentView(this, R.layout.main_activity);
//error in all the lines below saying cannot resolve button-----(where ---- denotes the specific terms of the button)
binding.buttonDot.setOnClickListener(new View.OnClickListener(){
#Override
public void onClick(View view){
binding.editText.setText(binding.editText.getText() + ".");
}
});
binding.buttonZero.setOnCLickListener(new View.OnClickListener(){
#Override
public void onClick(View view){
binding.editText.setText(binding.editText.getText() + "0");
}
});
binding.buttonOne.setOnCLickListener(new View.OnClickListener(){
#Override
public void onClick(View view){
binding.editText.setText(binding.editText.getText() + "1");
}
});
binding.buttonTwo.setOnCLickListener(new View.OnClickListener(){
#Override
public void onClick(View view){
binding.editText.setText(binding.editText.getText() + "2");
}
});
binding.buttonThree.setOnCLickListener(new View.OnClickListener(){
#Override
public void onClick(View view){
binding.editText.setText(binding.editText.getText() + "3");
}
});
binding.buttonFour.setOnCLickListener(new View.OnClickListener(){
#Override
public void onClick(View view){
binding.editText.setText(binding.editText.getText() + "4");
}
});
binding.buttonFive.setOnCLickListener(new View.OnClickListener(){
#Override
public void onClick(View view){
binding.editText.setText(binding.editText.getText() + "5");
}
});
binding.buttonSix.setOnCLickListener(new View.OnClickListener(){
#Override
public void onClick(View view){
binding.editText.setText(binding.editText.getText() + "6");
}
});
binding.buttonSeven.setOnCLickListener(new View.OnClickListener(){
#Override
public void onClick(View view){
binding.editText.setText(binding.editText.getText() + "7");
}
});
binding.buttonEight.setOnCLickListener(new View.OnClickListener(){
#Override
public void onClick(View view){
binding.editText.setText(binding.editText.getText() + "8");
}
});
binding.buttonNine.setOnCLickListener(new View.OnClickListener(){
#Override
public void onClick(View view){
binding.editText.setText(binding.editText.getText() + "9");
}
});
binding.buttonLeftC.setOnCLickListener(new View.OnClickListener(){
#Override
public void onClick(View view){
binding.editText.setText(binding.editText.getText() + "(");
}
});
binding.buttonRightC.setOnCLickListener(new View.OnClickListener(){
#Override
public void onClick(View view){
binding.editText.setText(binding.editText.getText() + ")");
}
});
binding.buttonExp.setOnCLickListener(new View.OnClickListener(){
#Override
public void onClick(View view){
computeCalculation();
ADVANCE_ACTION = EXP;
binding.infoTextView.setText(decimalFormat.format(valueOne) + "EXP");
binding.editText.setText(null);
}
});
binding.buttonPie.setOnCLickListener(new View.OnClickListener(){
#Override
public void onClick(View view){
computeCalculation();
ADVANCE_ACTION = PIE;
binding.infoTextView.setText(decimalFormat.format(valueOne) + "PIE");
binding.editText.setText(null);
}
});
binding.buttonAdd.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View view) {
computeCalculation();
CURRENT_ACTION = ADD;
binding.infoTextView.setText(decimalFormat.format(valueOne) + "+");
binding.editText.setText(null);
}
});
binding.buttonSubtract.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View view) {
computeCalculation();
CURRENT_ACTION = SUBTRACT;
binding.infoTextView.setText(decimalFormat.format(valueOne) + "-");
binding.editText.setText(null);
}
});
binding.buttonMultiply.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View view) {
computeCalculation();
CURRENT_ACTION = MULTIPlY;
binding.infoTextView.setText(decimalFormat.format(valueOne) + "*");
binding.editText.setText(null);
}
});
binding.buttonDivide.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View view) {
computeCalculation();
CURRENT_ACTION = DIVIDE;
binding.infoTextView.setText(decimalFormat.format(valueOne) + "/");
binding.editText.setText(null);
}
});
binding.buttonFact.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View view) {
computeCalculation();
CURRENT_ACTION = FACT;
binding.infoTextView.setText(decimalFormat.format(valueOne) + "!");
binding.editText.setText(null);
}
});
binding.buttonPow.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View view) {
computeCalculation();
CURRENT_ACTION = POWER;
binding.infoTextView.setText(decimalFormat.format(valueOne) + "^");
binding.editText.setText(null);
}
});
binding.buttonSqrt.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View view) {
computeCalculation();
ADVANCE_ACTION = SQRT;
binding.infoTextView.setText("SQRT(" + decimalFormat.format(valueOne) + ")");
binding.editText.setText(null);
}
});
binding.buttonSine.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View view) {
computeCalculation();
ADVANCE_ACTION = SIN;
binding.infoTextView.setText("SIN(" + decimalFormat.format(valueOne) + ")");
binding.editText.setText(null);
}
});
binding.buttonCosine.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View view) {
computeCalculation();
ADVANCE_ACTION = COS;
binding.infoTextView.setText("COS(" + decimalFormat.format(valueOne) + ")");
binding.editText.setText(null);
}
});
binding.buttonTangent.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View view) {
computeCalculation();
ADVANCE_ACTION = TAN;
binding.infoTextView.setText("TAN(" + decimalFormat.format(valueOne) + ")");
binding.editText.setText(null);
}
});
binding.buttonLog.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View view) {
computeCalculation();
ADVANCE_ACTION = LOG;
binding.infoTextView.setText("LOG(" + decimalFormat.format(valueOne) + ")");
binding.editText.setText(null);
}
});
binding.buttonEqual.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View view) {
computeCalculation();
binding.infoTextView.setText(binding.infoTextView.getText().toString() +
decimalFormat.format(valueTwo) + " = " + decimalFormat.format(valueOne));
valueOne = Double.NaN;
CURRENT_ACTION = '0';
}
});
binding.buttonClear.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View view) {
if(binding.editText.getText().length() > 0) {
CharSequence currentText = binding.editText.getText();
binding.editText.setText(currentText.subSequence(0, currentText.length()-1));
}
else {
valueOne = Double.NaN;
valueTwo = Double.NaN;
binding.editText.setText("");
binding.infoTextView.setText("");
}
}
});
}
private void computeCalculation() {
if(!Double.isNaN(valueOne)) {
valueTwo = Double.parseDouble(binding.editText.getText().toString());
binding.editText.setText(null);
if(CURRENT_ACTION == ADD)
valueOne = this.valueOne + valueTwo;
else if(CURRENT_ACTION == SUBTRACT)
valueOne = this.valueOne - valueTwo;
else if(CURRENT_ACTION == MULTIPlY)
valueOne = this.valueOne * valueTwo;
else if(CURRENT_ACTION == DIVIDE)
valueOne = this.valueOne / valueTwo;
else if(CURRENT_ACTION == FACT)
{
int i,valueThree = 1;
for(i=(int) valueOne;i>0;i--) //type conversion
{
valueThree *= i;
}
}
else if(CURRENT_ACTION == POWER)
valueOne = Math.pow(valueOne,valueTwo);
else if(ADVANCE_ACTION == SQRT)
valueOne = Math.sqrt(valueOne);
else if(ADVANCE_ACTION == SIN)
valueOne = Math.sin(valueOne);
else if(ADVANCE_ACTION == COS)
valueOne = Math.cos(valueOne);
else if(ADVANCE_ACTION == TAN)
valueOne = Math.tan(valueOne);
else if(ADVANCE_ACTION == LOG)
valueOne = Math.log(valueOne);
else if(ADVANCE_ACTION == PIE)
valueOne = Math.PI;
else if(ADVANCE_ACTION == EXP)
valueOne = Math.E;
}
else {
try {
valueOne = Double.parseDouble(binding.editText.getText().toString());
}
catch (Exception e){}
}
}
}
this is my xml file
main_activity.xml
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="#+id/main_activity"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context="com.example.anant.scientificcalculator.MainActivity">
<TextView
android:id="#+id/infoTextView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="30dp"
android:textSize="30sp" />
<EditText
android:id="#+id/editText"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="#id/infoTextView"
android:enabled="false"
android:gravity="bottom"
android:hint="0"
android:inputType="numberDecimal"
android:lines="2"
android:maxLines="2"
android:textAlignment="textEnd"
android:textColor="#android:color/black"
android:textSize="40sp" />
<Button
android:id="#+id/buttonFact"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#id/editText"
android:text="#string/buttonFact"
android:textSize="20sp" />
<Button
android:id="#+id/buttonPow"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#id/editText"
android:layout_toRightOf="#id/buttonFact"
android:text="#string/buttonPow"
android:textSize="20sp" />
<Button
android:id="#+id/buttonSqrt"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#id/editText"
android:layout_toRightOf="#id/buttonPow"
android:text="#string/buttonSqrt"
android:textSize="20sp" />
<Button
android:id="#+id/buttonClear"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_toRightOf="#id/buttonSqrt"
android:layout_below="#id/editText"
android:text="#string/buttonClear"
android:textSize="20sp" />
<Button
android:id="#+id/buttonSine"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#id/buttonFact"
android:text="#string/buttonSine"
android:textSize="20sp" />
<Button
android:id="#+id/buttonCosine"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#id/buttonPow"
android:layout_toRightOf="#id/buttonSine"
android:text="#string/buttonCosine"
android:textSize="20sp" />
<Button
android:id="#+id/buttonTangent"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#id/buttonSqrt"
android:layout_toRightOf="#id/buttonCosine"
android:text="#string/buttonTangent"
android:textSize="20sp" />
<Button
android:id="#+id/buttonLog"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#id/buttonClear"
android:layout_toRightOf="#id/buttonTangent"
android:text="#string/buttonLog"
android:textSize="20sp" />
<Button
android:id="#+id/buttonLeftC"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#id/buttonSine"
android:text="#string/buttonLeftC"
android:textSize="20sp" />
<Button
android:id="#+id/buttonRightC"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#id/buttonCosine"
android:layout_toRightOf="#id/buttonLeftC"
android:text="#string/buttonRightC"
android:textSize="20sp" />
<Button
android:id="#+id/buttonExp"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#id/buttonTangent"
android:layout_toRightOf="#id/buttonRightC"
android:text="#string/buttonExp"
android:textSize="20sp" />
<Button
android:id="#+id/buttonPie"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#id/buttonLog"
android:layout_toRightOf="#id/buttonExp"
android:text="#string/buttonPie"
android:textSize="20sp" />
<Button
android:id="#+id/buttonSeven"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#id/buttonLeftC"
android:text="#string/buttonSeven"
android:textSize="20sp" />
<Button
android:id="#+id/buttonEight"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#id/buttonRightC"
android:layout_toRightOf="#id/buttonSeven"
android:text="#string/buttonEight"
android:textSize="20sp" />
<Button
android:id="#+id/buttonNine"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#id/buttonExp"
android:layout_toRightOf="#id/buttonEight"
android:text="#string/buttonNine"
android:textSize="20sp" />
<Button
android:id="#+id/buttonFour"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#id/buttonSeven"
android:text="#string/buttonFour"
android:textSize="20sp" />
<Button
android:id="#+id/buttonFive"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#id/buttonEight"
android:layout_toRightOf="#id/buttonFour"
android:text="#string/buttonFive"
android:textSize="20sp" />
<Button
android:id="#+id/buttonSix"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#id/buttonNine"
android:layout_toRightOf="#id/buttonFive"
android:text="#string/buttonSix"
android:textSize="20sp" />
<Button
android:id="#+id/buttonOne"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#id/buttonFour"
android:text="#string/buttonOne"
android:textSize="20sp" />
<Button
android:id="#+id/buttonTwo"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#id/buttonFive"
android:layout_toRightOf="#id/buttonOne"
android:text="#string/buttonTwo"
android:textSize="20sp" />
<Button
android:id="#+id/buttonThree"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#id/buttonSix"
android:layout_toRightOf="#id/buttonTwo"
android:text="#string/buttonThree"
android:textSize="20sp" />
<Button
android:id="#+id/buttonDot"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#id/buttonOne"
android:text="#string/buttonDot"
android:textSize="20sp" />
<Button
android:id="#+id/buttonZero"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#id/buttonTwo"
android:layout_toRightOf="#id/buttonDot"
android:text="#string/buttonZero"
android:textSize="20sp" />
<Button
android:id="#+id/buttonEqual"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignRight="#id/buttonNine"
android:layout_below="#id/buttonThree"
android:text="#string/buttonEqual"
android:textSize="20sp" />
<Button
android:id="#+id/buttonDivide"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignTop="#id/buttonNine"
android:layout_toRightOf="#id/buttonNine"
android:text="#string/buttonDIvide"
android:textSize="20sp" />
<Button
android:id="#+id/buttonMultiply"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignTop="#id/buttonSix"
android:layout_toRightOf="#id/buttonSix"
android:text="#string/buttonMultiply"
android:textSize="20sp" />
<Button
android:id="#+id/buttonSubtract"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignTop="#id/buttonThree"
android:layout_toRightOf="#id/buttonThree"
android:text="#string/buttonSubtract"
android:textSize="20sp" />
<Button
android:id="#+id/buttonAdd"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignTop="#id/buttonEqual"
android:layout_toRightOf="#id/buttonEqual"
android:text="#string/buttonAdd"
android:textSize="20sp" />
</RelativeLayout>

You need to uncomment out:
//import com.example.anant.scientificcalculator.databinding.MainActivityBinding;
That is an autogenerated class for your data binding. You need it. Make it look like this:
com.example.anant.scientificcalculator.databinding.MainActivityBinding;
Secondly, your XML file isn't correct, it should have its RelativeLayout wrapped in a layout tag, like so:
<layout>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="#+id/main_activity"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context="com.example.anant.scientificcalculator.MainActivity">
...
</layout>
After you do that, do a clean and rebuild, and I think you should be good to go.

Uncomment
import com.example.anant.scientificcalculator.databinding.MainActivityBinding;
And wrap your layout under <layout> tag.

Related

ID value returning null

I am new to android programming and would like some help or advise as to why whenever I try and update records in the database by clicking on the update button the id that is meant to passed through is null so it wont update. How do I get it so that the Id is not null when updating.
DatabaseHelper.java
package com.example.warre.sqlliteapp;
import android.content.ContentValues;
import android.content.Context;
import android.database.Cursor;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteOpenHelper;
public class DatabaseHelper extends SQLiteOpenHelper {
public static final String DATABASE_NAME = "tracker.db";
public static final String TABLE_NAME = "tracker_table";
public static final String COL_1 = "ID";
public static final String COL_2 = "SALES";
public static final String COL_3 = "FOLLOW";
public static final String COL_4 = "DONE";
public static final String COL_5 = "LEADER";
public static final String COL_6 = "TRAIN";
public DatabaseHelper(Context context) {
super(context, DATABASE_NAME, null, 1);
}
#Override
public void onCreate(SQLiteDatabase db) {
db.execSQL("create table " + TABLE_NAME +" (ID INTEGER PRIMARY KEY AUTOINCREMENT,SALES INTEGER,FOLLOW INTEGER,DONE INTEGER, LEADER INTEGER, TRAIN INTEGER)");
}
#Override
public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
db.execSQL("DROP TABLE IF EXISTS "+TABLE_NAME);
onCreate(db);
}
public boolean insertData(String sales,String follow,String done, String leader, String train) {
SQLiteDatabase db = this.getWritableDatabase();
ContentValues contentValues = new ContentValues();
contentValues.put(COL_2,sales);
contentValues.put(COL_3,follow);
contentValues.put(COL_4,done);
contentValues.put(COL_5,leader);
contentValues.put(COL_6, train);
long result = db.insert(TABLE_NAME,null ,contentValues);
if(result == -1)
return false;
else
return true;
}
public Cursor getAllData() {
SQLiteDatabase db = this.getWritableDatabase();
Cursor res = db.rawQuery("select * from "+TABLE_NAME,null);
return res;
}
public boolean updateData(String id,String sales,String follow,String done, String leader, String train) {
SQLiteDatabase db = this.getWritableDatabase();
ContentValues contentValues = new ContentValues();
contentValues.put(COL_1,id);
contentValues.put(COL_2,sales);
contentValues.put(COL_3,follow);
contentValues.put(COL_4,done);
contentValues.put(COL_5, leader);
contentValues.put(COL_6, train);
db.update(TABLE_NAME, contentValues, "ID = ?",new String[] { id });
return true;
}
public Integer deleteData (String id) {
SQLiteDatabase db = this.getWritableDatabase();
return db.delete(TABLE_NAME, "ID = ?",new String[] {id});
}
}
MainActivity
The problem is happening in the updateData() where editTextId is getting null or returning null.
package com.example.warre.sqlliteapp;
import android.app.Activity;
import android.database.Cursor;
import android.os.Handler;
import android.support.v7.app.AlertDialog;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;
import android.widget.Toast;
import java.util.Timer;
import java.util.TimerTask;
public class MainActivity extends Activity {
DatabaseHelper myDb;
EditText editTextId;
TextView txtSales,txtFollow,txtDone,txtLeader,txtTrain, TimerValue;
Button btnAddData;
Button btnviewAll;
Button btnDelete;
Button SALES,FOLLOW,DONE,LEADER,TRAIN, STOP, REPORT;
int countSales = 0;
int countFollow = 0;
int countDone = 0;
int nCounter = 0;
String timeName;
TimerTask mTimerTask;
final Handler handler = new Handler();
Timer t = new Timer();
Button btnviewUpdate;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_money);
myDb = new DatabaseHelper(this);
TimerValue = (TextView) findViewById(R.id.tv_current_timeV2);
txtSales = (TextView) findViewById(R.id.textSales);
txtFollow = (TextView) findViewById(R.id.textFollow);
txtDone = (TextView) findViewById(R.id.textDone);
txtLeader = (TextView) findViewById(R.id.leaderTime);
txtTrain = (TextView) findViewById(R.id.trainTime);
SALES = (Button) findViewById(R.id.btnSales);
FOLLOW = (Button) findViewById(R.id.btnFollow);
DONE = (Button) findViewById(R.id.btnDone);
LEADER = (Button) findViewById(R.id.btnLeader);
TRAIN = (Button) findViewById(R.id.btnTrain);
STOP = (Button) findViewById(R.id.btnStop);
REPORT = (Button) findViewById(R.id.button_details);
editTextId = (EditText)findViewById(R.id.editText_id);
btnAddData = (Button)findViewById(R.id.button_add);
btnviewAll = (Button)findViewById(R.id.button_viewAll);
btnviewUpdate= (Button)findViewById(R.id.button_update);
btnDelete= (Button)findViewById(R.id.button_delete);
TimerValue.setText("00:00:00");
txtSales.setText("0");
txtFollow.setText("0");
txtDone.setText("0");
txtLeader.setText("00:00:00");
txtTrain.setText("00:00:00");
viewAll();
AddData();
UpdateData();
CountSales();
CountFollow();
CountDone();
TimeLeader();
TimeTrain();
StopTime();
}
public void CountSales() {
SALES.setOnClickListener(
new View.OnClickListener() {
#Override
public void onClick(View v) {
countSales++;
txtSales.setText(String.valueOf(countSales));
}
}
);
}
public void CountFollow() {
FOLLOW.setOnClickListener(
new View.OnClickListener() {
#Override
public void onClick(View v) {
countFollow++;
txtFollow.setText(String.valueOf(countFollow));
}
}
);
}
public void CountDone() {
DONE.setOnClickListener(
new View.OnClickListener() {
#Override
public void onClick(View v) {
countDone++;
txtDone.setText(String.valueOf(countDone));
}
}
);
}
public void TimeLeader() {
LEADER.setOnClickListener(
new View.OnClickListener() {
#Override
public void onClick(View v) {
SALES.setClickable(false);
FOLLOW.setClickable(false);
DONE.setClickable(false);
LEADER.setClickable(false);
TRAIN.setClickable(false);
timeName = "leader";
mTimerTask = new TimerTask() {
public void run() {
handler.post(new Runnable() {
public void run() {
nCounter++;
TimerValue.setText("" + Utils.secToString(Integer.parseInt(String.valueOf(nCounter))));
txtLeader.setText("" + Utils.secToString(Integer.parseInt(String.valueOf(nCounter))));
}
});
}};
t.schedule(mTimerTask, 200, 1000); //
}
}
);
}
public void TimeTrain() {
TRAIN.setOnClickListener(
new View.OnClickListener() {
#Override
public void onClick(View v) {
SALES.setClickable(false);
FOLLOW.setClickable(false);
DONE.setClickable(false);
LEADER.setClickable(false);
TRAIN.setClickable(false);
timeName = "train";
mTimerTask = new TimerTask() {
public void run() {
handler.post(new Runnable() {
public void run() {
nCounter++;
TimerValue.setText("" + Utils.secToString(Integer.parseInt(String.valueOf(nCounter))));
txtTrain.setText("" + Utils.secToString(Integer.parseInt(String.valueOf(nCounter))));
}
});
}};
t.schedule(mTimerTask, 200, 1000); //
}
}
);
}
public void StopTime() {
STOP.setOnClickListener(
new View.OnClickListener() {
#Override
public void onClick(View v) {
SALES.setClickable(true);
FOLLOW.setClickable(true);
DONE.setClickable(true);
LEADER.setClickable(true);
TRAIN.setClickable(true);
if (mTimerTask != null) {
TimerValue.setText("" + Utils.secToString(Integer.parseInt(String.valueOf(nCounter))));
mTimerTask.cancel();
if (timeName == "leader") {
TimerValue.setText(Utils.secToString(0));
txtLeader.setText("" + Utils.secToString(Integer.parseInt(String.valueOf(nCounter))));
} else if (timeName == "train") {
TimerValue.setText(Utils.secToString(0));
txtTrain.setText("" + Utils.secToString(Integer.parseInt(String.valueOf(nCounter))));
}
}
}
}
);
}
public void AddData() {
btnAddData.setOnClickListener(
new View.OnClickListener() {
#Override
public void onClick(View v) {
boolean isInserted = myDb.insertData(txtSales.getText().toString(),
txtFollow.getText().toString(),
txtDone.getText().toString(), txtLeader.getText().toString(), txtTrain.getText().toString() );
if(isInserted == true) {
Toast.makeText(MainActivity.this, "Data Inserted", Toast.LENGTH_LONG).show();
btnAddData.setVisibility(v.GONE);
}
else
Toast.makeText(MainActivity.this,"Data not Inserted",Toast.LENGTH_LONG).show();
}
}
);
}
public void UpdateData() {
btnviewUpdate.setOnClickListener(
new View.OnClickListener() {
#Override
public void onClick(View v) {
boolean isUpdate = myDb.updateData(editTextId.getText().toString(),
txtSales.getText().toString(),
txtFollow.getText().toString(),
txtDone.getText().toString(), txtLeader.getText().toString(), txtTrain.getText().toString() );
if(isUpdate == true)
Toast.makeText(MainActivity.this,"Data Update",Toast.LENGTH_LONG).show();
else
Toast.makeText(MainActivity.this,"Data not Updated",Toast.LENGTH_LONG).show();
}
}
);
}
public void viewAll() {
REPORT.setOnClickListener(
new View.OnClickListener() {
#Override
public void onClick(View v) {
Cursor res = myDb.getAllData();
if(res.getCount() == 0) {
// show message
showMessage("Error","Nothing found");
return;
}
StringBuffer buffer = new StringBuffer();
while (res.moveToNext()) {
buffer.append("Id :"+ res.getString(0)+"\n");
buffer.append("Sales :"+ res.getString(1)+"\n");
buffer.append("Follow :"+ res.getString(2)+"\n");
buffer.append("Done :"+ res.getString(3)+"\n");
buffer.append("Leader :"+ res.getString(4)+"\n");
buffer.append("Train :"+ res.getString(5)+"\n" );
}
// Show all data
showMessage("Data",buffer.toString());
}
}
);
}
public void showMessage(String title,String Message){
AlertDialog.Builder builder = new AlertDialog.Builder(this);
builder.setCancelable(true);
builder.setTitle(title);
builder.setMessage(Message);
builder.show();
}
}
activity_money
<?xml version="1.0" encoding="utf-8"?>
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#000000">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="horizontal">
</LinearLayout>
<TextView
android:layout_width="match_parent"
android:layout_height="match_parent" />
<TextView
android:id="#+id/tv_current_timeV2"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center"
android:text="00:00:00"
android:textAppearance="?android:attr/textAppearanceLarge"
android:textColor="#android:color/holo_green_light"
android:textSize="38dp"
android:textStyle="bold" />
<TextView
android:layout_width="match_parent"
android:layout_height="match_parent" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="horizontal">
<Button
android:id="#+id/btnSales"
android:layout_width="168dp"
android:layout_height="match_parent"
android:layout_marginLeft="100dp"
android:onClick="onClick"
android:text="SALES" />
<TextView
android:id="#+id/textSales"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:text="0"
android:textStyle="bold"
android:textColor="#color/colorWhite"
android:gravity="center"/>
</LinearLayout>
<TextView
android:layout_width="match_parent"
android:layout_height="match_parent" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="horizontal">
<Button
android:id="#+id/btnFollow"
android:layout_width="168dp"
android:layout_height="match_parent"
android:layout_marginLeft="100dp"
android:onClick="onClick"
android:text="FOLLOW"
/>
<TextView
android:id="#+id/textFollow"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:text="0"
android:textStyle="bold"
android:textColor="#color/colorWhite"
android:gravity="center"/>
</LinearLayout>
<TextView
android:layout_width="match_parent"
android:layout_height="match_parent" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="horizontal">
<Button
android:id="#+id/btnDone"
android:layout_width="168dp"
android:layout_height="match_parent"
android:onClick="onClick"
android:layout_marginLeft="100dp"
android:text="DONE" />
<TextView
android:id="#+id/textDone"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:text="0"
android:textStyle="bold"
android:textColor="#color/colorWhite"
android:gravity="center"/>
</LinearLayout>
<TextView
android:layout_width="match_parent"
android:layout_height="match_parent" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="horizontal">
<Button
android:id="#+id/btnLeader"
android:layout_width="168dp"
android:layout_height="match_parent"
android:layout_marginLeft="100dp"
android:onClick="onClick"
android:text="LEADER" />
<TextView
android:id="#+id/leaderTime"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:text="00:00:00"
android:textStyle="bold"
android:textColor="#color/colorWhite"
android:gravity="center"/>
</LinearLayout>
<TextView
android:layout_width="match_parent"
android:layout_height="match_parent" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="horizontal">
<Button
android:id="#+id/btnTrain"
android:layout_width="168dp"
android:layout_height="match_parent"
android:onClick="onClick"
android:layout_marginLeft="100dp"
android:text="TRAIN" />
<TextView
android:id="#+id/trainTime"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:text="00:00:00"
android:textStyle="bold"
android:textColor="#color/colorWhite"
android:gravity="center"/>
</LinearLayout>
<TextView
android:layout_width="match_parent"
android:layout_height="match_parent" />
<Button
android:id="#+id/btnStop"
android:layout_width="168dp"
android:layout_height="match_parent"
android:layout_marginLeft="100dp"
android:onClick="onClick"
android:text="STOP" />
<TextView
android:layout_width="match_parent"
android:layout_height="match_parent" />
<TextView
android:layout_width="match_parent"
android:layout_height="match_parent" />
<TextView
android:layout_width="match_parent"
android:layout_height="match_parent" />
<Button
android:id="#+id/button_details"
android:layout_width="168dp"
android:layout_height="match_parent"
android:layout_marginLeft="5dp"
android:text="REPORT"
android:textColor="#color/colorBlack"
android:onClick="onClick"
android:textStyle="bold"/>
<Button
android:id="#+id/button_add"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:layout_below="#+id/editText_Marks"
android:layout_marginTop="76dp"
android:text="Add Data" />
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Update"
android:id="#+id/button_update"
android:layout_below="#+id/button_add"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true" />
</LinearLayout>
</ScrollView>
Error Log
Eror Log
Okay so your cause of error is because of this line
editTextId = (EditText)findViewById(R.id.editText_id);
as there is no EditText in your activity_money.xml layout and you are trying to get its reference so you are getting null reference.
First add it in xml or remove the edittext lines from your java file.

How to link tablerow content to checkbox?

Imagine I have checkbox with criteria in main activity and table in second activity. I want to link table to checkbox so for example when price and mileage is checked, only price and mileage columns are displayed. But when nothing is checked table is not appearing.I would really appreciate if someone could explain how to do it or give me a link to tutorial.
MainActivity.java:
package todo.beginner.com.carchooser2;
import android.content.Intent;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.view.View;
import android.widget.Button;
import android.widget.CheckBox;
import android.widget.Toast;
import static todo.beginner.com.carchooser2.R.id.checkBoxPrice;
import static todo.beginner.com.carchooser2.R.id.checkBoxGas;
import static todo.beginner.com.carchooser2.R.id.checkBoxYear;
import static todo.beginner.com.carchooser2.R.id.checkBoxMileage;
import static todo.beginner.com.carchooser2.R.id.checkBoxCapacity;
public class MainActivity extends AppCompatActivity {
private CheckBox check1, check2, check3, check4, check5;
private static Button button_next;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
addListenerToCeckBox();
OnClickButtonListener();
}
public void OnClickButtonListener() {
button_next = (Button)findViewById(R.id.button);
button_next.setOnClickListener(
new View.OnClickListener() {
#Override
public void onClick(View v) {
Intent intent = new Intent(MainActivity.this, SecondActivity.class);
startActivity(intent);
}
}
);
new View.OnClickListener() {
#Override
public void onClick(View v) {
Intent intent = new Intent(MainActivity.this, SecondActivity.class);
intent.putExtra("Price", check1.isChecked());
startActivity(intent);
}
};
new View.OnClickListener() {
#Override
public void onClick(View v) {
Intent intent = new Intent(MainActivity.this, SecondActivity.class);
intent.putExtra("Year", check2.isChecked());
startActivity(intent);
}
};
new View.OnClickListener() {
#Override
public void onClick(View v) {
Intent intent = new Intent(MainActivity.this, SecondActivity.class);
intent.putExtra("Capacity", check3.isChecked());
startActivity(intent);
}
};
new View.OnClickListener() {
#Override
public void onClick(View v) {
Intent intent = new Intent(MainActivity.this, SecondActivity.class);
intent.putExtra("Gas", check4.isChecked());
startActivity(intent);
}
};
new View.OnClickListener() {
#Override
public void onClick(View v) {
Intent intent = new Intent(MainActivity.this, SecondActivity.class);
intent.putExtra("Mileage", check5.isChecked());
startActivity(intent);
}
};
}
public void addListenerToCeckBox() {
check1 = (CheckBox)findViewById(checkBoxCena);
check1.setOnClickListener(
new View.OnClickListener() {
#Override
public void onClick(View v) {
if (((CheckBox)v).isChecked()){
Toast.makeText(MainActivity.this,
"Price is chosen", Toast.LENGTH_LONG).show();
}
}
}
);
check2 = (CheckBox)findViewById(checkBoxGads);
check2.setOnClickListener(
new View.OnClickListener() {
#Override
public void onClick(View v) {
if (((CheckBox)v).isChecked()){
Toast.makeText(MainActivity.this,
"Year is chosen", Toast.LENGTH_LONG).show();
}
}
}
);
check3 = (CheckBox)findViewById(checkBoxTilpums);
check3.setOnClickListener(
new View.OnClickListener() {
#Override
public void onClick(View v) {
if (((CheckBox)v).isChecked()){
Toast.makeText(MainActivity.this,
"Engine capacity is chosen", Toast.LENGTH_LONG).show();
}
}
}
);
check4 = (CheckBox)findViewById(checkBoxDegviela);
check4.setOnClickListener(
new View.OnClickListener() {
#Override
public void onClick(View v) {
if (((CheckBox)v).isChecked()){
Toast.makeText(MainActivity.this,
"Gas consumption is chosen", Toast.LENGTH_LONG).show();
}
}
}
);
check5 = (CheckBox)findViewById(checkBoxNobraukums);
check5.setOnClickListener(
new View.OnClickListener() {
#Override
public void onClick(View v) {
if (((CheckBox)v).isChecked()){
Toast.makeText(MainActivity.this,
"Mileage is chosen", Toast.LENGTH_LONG).show();
}
}
}
);
}
}
activity_main.xml:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="#+id/activity_main"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingBottom="#dimen/activity_vertical_margin"
android:paddingLeft="#dimen/activity_horizontal_margin"
android:paddingRight="#dimen/activity_horizontal_margin"
android:paddingTop="#dimen/activity_vertical_margin"
tools:context="todo.beginner.com.carchooser2.MainActivity">
<CheckBox
android:text="Price"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="#+id/checkBoxPrice"
android:layout_alignParentTop="true"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:layout_marginTop="67dp" />
<CheckBox
android:text="Year"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="#+id/checkBoxPrice"
android:layout_alignRight="#+id/checkBoxPrice"
android:layout_alignEnd="#+id/checkBoxPrice"
android:layout_marginTop="33dp"
android:id="#+id/checkBoxYear" />
<CheckBox
android:text="Capacity"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="37dp"
android:id="#+id/checkBoxCapacity"
android:layout_below="#+id/checkBoxYear"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true" />
<CheckBox
android:text="Gas"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="#+id/checkBoxCapacity"
android:layout_alignRight="#+id/checkBoxCapacity"
android:layout_alignEnd="#+id/checkBoxCapacity"
android:layout_marginTop="30dp"
android:id="#+id/checkBoxGas" />
<CheckBox
android:text="Mileage"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="#+id/checkBoxGas"
android:layout_alignRight="#+id/checkBoxGas"
android:layout_alignEnd="#+id/checkBoxGas"
android:layout_marginTop="33dp"
android:id="#+id/checkBoxMileage" />
<Button
android:text="Continue"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_centerHorizontal="true"
android:layout_marginBottom="31dp"
android:id="#+id/button" />
<TextView
android:text="Choose criteria!"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="8dp"
android:id="#+id/textView"
android:layout_alignParentTop="true"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true" />
</RelativeLayout>
SecondActivity.java:
package todo.beginner.com.carchooser2;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
public class SecondActivity extends AppCompatActivity {
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_second);
boolean hasPrice = getIntent().getBooleanExtra("Price", true);
boolean hasYear = getIntent().getBooleanExtra("Year", true);
boolean hasCapacity = getIntent().getBooleanExtra("Capacity", true);
boolean hasGas = getIntent().getBooleanExtra("Gas", true);
boolean hasMileage = getIntent().getBooleanExtra("Mileage", true);
TextView Price = (TextView) findViewById(R.id.Price); // you will need to create this id in your layout
Price.setVisibility(hasPrice ? View.VISIBLE : View.GONE);
TextView Year = (TextView) findViewById(R.id.Year); // you will need to create this id in your layout
Year.setVisibility(hasYear ? View.VISIBLE : View.GONE);
TextView Capacity = (TextView) findViewById(R.id.Capacity); // you will need to create this id in your layout
Capacity.setVisibility(hasCapacity ? View.VISIBLE : View.GONE);
TextView Gas = (TextView) findViewById(R.id.Gas); // you will need to create this id in your layout
Gas.setVisibility(hasGas ? View.VISIBLE : View.GONE);
TextView Mileage = (TextView) findViewById(R.id.Mileage); // you will need to create this id in your layout
Mileage.setVisibility(hasMileage ? View.VISIBLE : View.GONE);
}
}
activity_second.xml:
<?xml version="1.0" encoding="utf-8"?>
<TableLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginTop="10dp">
<TableRow
android:background="#607D8B"
android:padding="5dp">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:id="#+id/Name"
android:text="Car Name" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:id="#+id/Price"
android:text="Price" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:id="#+id/Year"
android:text="Year" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:id="#+id/Gas"
android:text="Gas" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:id="#+id/Mileage"
android:text="Mileage" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:id="#+id/Capacity"
android:text="Capacity" />
</TableRow>
<TableRow
android:background="#ECEFF1"
android:padding="5dp">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="Audi" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="5000" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="2001" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="7" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="280000" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="2.5" />
</TableRow>
</TableLayout>
In your OnClickButtonListener, you are declaring a lot of new View.OnClickListener()s, but you are just creating the implementations then not doing anything with them. Those should all be removed. Your method should look like this:
public void OnClickButtonListener() {
button_next = (Button)findViewById(R.id.button);
button_next.setOnClickListener(
new View.OnClickListener() {
#Override
public void onClick(View v) {
Intent intent = new Intent(MainActivity.this, SecondActivity.class);
intent.putExtra("Price", check1.isChecked());
intent.putExtra("Year", check2.isChecked());
intent.putExtra("Capacity", check3.isChecked());
intent.putExtra("Gas", check4.isChecked());
intent.putExtra("Mileage", check5.isChecked());
startActivity(intent);
}
}
);
}
See how it parallels with the code in the onCreate method in the SecondActivity?
After this change, you should see about what you expect to see.
Your first step would put be to create an Intent that has the values of the checkboxes, and pass that to the second activity:
Intent intent = new Intent(MainActivity.this, SecondActivity.class);
intent.putExtra("name", check1.isChecked());
// same for other checkboxes
startActivity(intent);
Next, in your SecondActivity access those values:
boolean hasName = getIntent().getBooleanExtra("name", true);
When you are creating your TableRow, set the visibility based on the values:
TextView carName = (TextView) findViewById(R.id.car_name); // you will need to create this id in your layout
carName.setVisibility(hasName ? View.VISIBLE : View.GONE);
Remember, if nothing is checked then you won't see anything, so you should probably start MainActivity with all the checkboxes checked to begin with.

how to switch from a fragment in a fragmentActivity to the Activity in android

I have a fragment class in with I am having few fragment tabs. each of them are opening another dedicated fragment. but I want to change one fragment to open an activity class. I have gone through many examples but didn't the problem solve. everytime my application goes crashed.
here is my fragment class.
import java.io.File;
import java.util.ArrayList;
import java.util.List;
import org.apache.http.NameValuePair;
import android.app.Activity;
import android.app.Dialog;
import android.content.Context;
import android.content.Intent;
import android.content.SharedPreferences;
import android.content.SharedPreferences.Editor;
import android.graphics.Bitmap;
import android.graphics.Color;
import android.graphics.Typeface;
import android.os.AsyncTask;
import android.os.Bundle;
import android.preference.PreferenceManager;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentManager;
import android.support.v4.app.FragmentTransaction;
import android.text.Editable;
import android.text.TextWatcher;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.ViewGroup;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.ArrayAdapter;
import android.widget.Button;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.ListView;
import android.widget.TextView;
import android.widget.Toast;
import com.appdupe.flamer.LoginUsingFacebook;
import com.appdupe.flamer.LoginUsingFacebook.BackGroundTaskForFetchingDataFromFaceBook;
import com.actionbarsherlock.app.SherlockFragmentActivity;
import com.androidquery.AQuery;
import com.androidquery.callback.ImageOptions;
import com.appdupe.androidpushnotifications.ChatActivity;
import com.appdupe.flamer.QuestionsActivity;
import com.appdupe.flamer.pojo.LikeMatcheddataForListview;
import com.appdupe.flamer.pojo.LikedMatcheData;
import com.appdupe.flamer.pojo.Likes;
import com.appdupe.flamer.utility.AlertDialogManager;
import com.appdupe.flamer.utility.AppLog;
import com.appdupe.flamer.utility.ConnectionDetector;
import com.appdupe.flamer.utility.Constant;
import com.appdupe.flamer.utility.ScalingUtilities;
import com.appdupe.flamer.utility.ScalingUtilities.ScalingLogic;
import com.appdupe.flamer.utility.SessionManager;
import com.appdupe.flamer.utility.Ultilities;
import com.appdupe.flamer.utility.Utility;
import com.appdupe.flamerchat.db.DatabaseHandler;
import com.appdupe.flamernofb.R;
import com.google.gson.Gson;
import com.jeremyfeinstein.slidingmenu.lib.SlidingMenu;
import com.jeremyfeinstein.slidingmenu.lib.SlidingMenu.OnOpenListener;
public class MainActivity extends SherlockFragmentActivity implements
OnClickListener, OnOpenListener {
// MainLayout mLayout;
private static final String TAG = "MainActivity";
private ListView matcheslistview;
Button btMenu;
private Button buttonRightMenu;
TextView tvTitle;
private Typeface topbartextviewFont;
private Editor editor;
private SharedPreferences preferences;
private EditText etSerchFriend;
double mLatitude = 0;
double mLongitude = 0;
double dLatitude = 0;
double dLongitude = 0;
// private Session.StatusCallback statusCallback = new
// SessionStatusCallback();
private Dialog mdialog;
// private boolean usersignup = false;
private boolean isProfileclicked = false;
private ArrayList<LikeMatcheddataForListview> arryList;
private MatchedDataAdapter adapter;
private ImageView profileimage;
private LinearLayout profilelayout, homelayout, messages, settinglayout,
invitelayout, questionLayout;
public SlidingMenu menu;
private boolean flagforHome, flagForProfile, flagForsetting;
// private AQuery aQuery;
private ImageOptions options;
private ConnectionDetector cd;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
// mLayout = (MainLayout)
// this.getLayoutInflater().inflate(R.layout.slidmenuxamplemainactivity,
// null);
// setContentView(mLayout);
cd = new ConnectionDetector(this);
preferences = PreferenceManager.getDefaultSharedPreferences(this);
editor = preferences.edit();
// aQuery = new AQuery(this);
options = new ImageOptions();
options.fileCache = true;
options.memCache = true;
setContentView(R.layout.slidmenuxamplemainactivity);
if (preferences.getBoolean(Constant.PREF_ISFIRST, true)) {
editor.putBoolean(Constant.PREF_ISFIRST, false);
editor.commit();
//startActivity(new Intent(this, QuestionsActivity.class));
}
tvTitle = (TextView) findViewById(R.id.activity_main_content_title);
topbartextviewFont = Typeface.createFromAsset(getAssets(),
"fonts/HelveticaLTStd-Light.otf");
tvTitle.setTypeface(topbartextviewFont);
tvTitle.setTextColor(Color.rgb(255, 255, 255));
tvTitle.setTextSize(20);
menu = new SlidingMenu(this);
menu.setMode(SlidingMenu.LEFT_RIGHT);
menu.setTouchModeAbove(SlidingMenu.TOUCHMODE_MARGIN);
menu.setShadowWidthRes(R.dimen.shadow_width);
menu.setShadowDrawable(R.drawable.shadow);
menu.setBehindOffsetRes(R.dimen.slidingmenu_offset);
menu.setFadeDegree(0.35f);
menu.attachToActivity(this, SlidingMenu.SLIDING_CONTENT);
Log.d(TAG, "onCreate before add menu ");
menu.setMenu(R.layout.leftmenu);
menu.setSecondaryMenu(R.layout.rightmenu);
Log.d(TAG, "onCreate add menu ");
menu.setSlidingEnabled(true);
Log.d(TAG, "onCreate finish");
// search
etSerchFriend = (EditText) menu
.findViewById(R.id.et_serch_right_side_menu);
// btnSerch = (Button) menu.findViewById(R.id.btn_serch_right_side);
View leftmenuview = menu.getMenu();
View rightmenuview = menu.getSecondaryMenu();
initLayoutComponent(leftmenuview, rightmenuview);
menu.setSecondaryOnOpenListner(this);
// lvMenuItems = getResources().getStringArray(R.array.menu_items);
// lvMenu.setAdapter(new
// ArrayAdapter<String>(this,android.R.layout.simple_list_item_1,
// lvMenuItems));
matcheslistview.setOnItemClickListener(new OnItemClickListener() {
#Override
public void onItemClick(AdapterView<?> arg0, View arg1, int arg2,
long arg3) {
// logDebug("setOnItemClickListener onItemClick arg2 "+arg2);
LikeMatcheddataForListview matcheddataForListview = (LikeMatcheddataForListview) arg0
.getItemAtPosition(arg2);
String faceboolid = matcheddataForListview.getFacebookid();
// logDebug(" background setOnItemClickListener onItemClick friend facebook id faceboolid "+faceboolid);
// logDebug(" background setOnItemClickListener onItemClick user facebook id faceboolid"+new
// SessionManager(MainActivity.this).getFacebookId());
Bundle mBundle = new Bundle();
mBundle.putString(Constant.FRIENDFACEBOOKID, faceboolid);
mBundle.putString(Constant.CHECK_FOR_PUSH_OR_NOT, "1");
Intent mIntent = new Intent(MainActivity.this,
ChatActivity.class);
mIntent.putExtras(mBundle);
startActivity(mIntent);
menu.toggle();
}
});
buttonRightMenu = (Button) findViewById(R.id.button_right_menu);
btMenu = (Button) findViewById(R.id.button_menu);
btMenu.setOnClickListener(new OnClickListener() {
#Override
public void onClick(View v) {
// Show/hide the menu
toggleMenu(v);
}
});
try {
profilelayout.setOnClickListener(this);
homelayout.setOnClickListener(this);
messages.setOnClickListener(this);
settinglayout.setOnClickListener(this);
invitelayout.setOnClickListener(this);
questionLayout.setOnClickListener(this);
} catch (Exception e) {
AppLog.handleException("oncreate Exception ", e);
}
// Bundle extras = getIntent().getExtras();
System.out.println("Get Intent done");
try {
FragmentManager fm = MainActivity.this.getSupportFragmentManager();
FragmentTransaction ft = fm.beginTransaction();
FindMatches fragment = new FindMatches();
ft.add(R.id.activity_main_content_fragment, fragment);
tvTitle.setText(getResources().getString(R.string.app_name));
ft.commit();
setProfilePick(profileimage);
} catch (Exception e) {
AppLog.handleException("onCreate Exception ", e);
}
Ultilities mUltilities = new Ultilities();
int imageHeightAndWidht[] = mUltilities
.getImageHeightAndWidthForAlubumListview(this);
arryList = new ArrayList<LikeMatcheddataForListview>();
adapter = new MatchedDataAdapter(this, arryList, imageHeightAndWidht);
matcheslistview.setAdapter(adapter);
// final SessionManager sessionManager = new SessionManager(this);
buttonRightMenu.setOnClickListener(new OnClickListener() {
#Override
public void onClick(View v) {
if (isProfileclicked) {
Intent mIntent = new Intent(MainActivity.this,
EditProfileNew.class);
startActivity(mIntent);
} else {
toggleRightMenu(v);
}
}
});
initSerchData();
}
private void initSerchData() {
etSerchFriend.addTextChangedListener(new TextWatcher() {
#Override
public void onTextChanged(CharSequence s, int start, int before,
int count) {
adapter.getFilter().filter(s.toString().trim());
}
#Override
public void beforeTextChanged(CharSequence s, int start, int count,
int after) {
}
#Override
public void afterTextChanged(Editable s) {
}
});
}
public void setMenuTouchFullScreenEnable(boolean isEnable) {
if (isEnable) {
menu.setTouchModeAbove(SlidingMenu.TOUCHMODE_FULLSCREEN);
} else {
menu.setTouchModeAbove(SlidingMenu.TOUCHMODE_NONE);
}
}
#Override
public void onOpen() {
AppLog.Log(TAG, "onOpen");
findLikedMatched();
}
#Override
protected void onResume() {
super.onResume();
AppLog.Log(TAG, " MainActivity onResume called");
}
private void setProfilePick(final ImageView userProfilImage) {
final Ultilities mUltilities = new Ultilities();
new Thread(new Runnable() {
#Override
public void run() {
final Bitmap bitmapimage = Utility.getBitmapFromURL(preferences
.getString(Constant.PREF_PROFILE_IMAGE_ONE, ""));
runOnUiThread(new Runnable() {
#Override
public void run() {
AppLog.Log(
TAG,
"Profile Image Url:"
+ preferences
.getString(
Constant.PREF_PROFILE_IMAGE_ONE,
""));
Bitmap cropedBitmap = null;
ScalingUtilities mScalingUtilities = new ScalingUtilities();
Bitmap mBitmap = null;
if (bitmapimage != null) {
cropedBitmap = mScalingUtilities
.createScaledBitmap(bitmapimage, 80, 80,
ScalingLogic.CROP);
bitmapimage.recycle();
mBitmap = mUltilities.getCircleBitmap(cropedBitmap,
1);
cropedBitmap.recycle();
userProfilImage.setImageBitmap(mBitmap);
// aQuery.id(userProfilImage).image(mBitmap);
} else {
}
}
});
}
}).start();
}
private void initLayoutComponent(View leftmenu, View rightmenu) {
matcheslistview = (ListView) rightmenu
.findViewById(R.id.menu_right_ListView);
profileimage = (ImageView) leftmenu.findViewById(R.id.profileimage);
profilelayout = (LinearLayout) leftmenu
.findViewById(R.id.profilelayout);
homelayout = (LinearLayout) leftmenu.findViewById(R.id.homelayout);
messages = (LinearLayout) leftmenu.findViewById(R.id.messages);
settinglayout = (LinearLayout) leftmenu
.findViewById(R.id.settinglayout);
invitelayout = (LinearLayout) leftmenu.findViewById(R.id.invitelayout);
/*questionLayout = (LinearLayout) leftmenu
.findViewById(R.id.questionLayout);*///devraj
}
private void findLikedMatched() {
AppLog.Log(TAG, "findLikedMatched");
String params[] = { preferences.getString(Constant.FACEBOOK_ID, "") };
new BackgroundTaskForFindLikeMatched().execute(params);
}
private class BackgroundTaskForFindLikeMatched extends
AsyncTask<String, Void, Void> {
private Ultilities mUltilities = new Ultilities();
private List<NameValuePair> getuserparameter;
private String likedmatchedata;
private LikedMatcheData matcheData;
private ArrayList<Likes> likesList;
private LikeMatcheddataForListview matcheddataForListview;
DatabaseHandler mDatabaseHandler = new DatabaseHandler(
MainActivity.this);
private boolean isResponseSuccess = true;
#Override
protected Void doInBackground(String... params) {
try {
File appDirectory = mUltilities
.createAppDirectoy(getResources().getString(
R.string.appdirectory));
AppLog.Log(TAG,
"BackgroundTaskForFindLikeMatched doInBackground appDirectory "
+ appDirectory);
File _picDir = new File(appDirectory, getResources().getString(
R.string.imagedirematchuserdirectory));
AppLog.Log(TAG,
"BackgroundTaskForFindLikeMatched doInBackground ");
getuserparameter = mUltilities.getUserLikedParameter(params);
AppLog.Log(TAG,
"BackgroundTaskForFindLikeMatched doInBackground getuserparameter "
+ getuserparameter);
likedmatchedata = mUltilities.makeHttpRequest(
Constant.getliked_url, Constant.methodeName,
getuserparameter);
AppLog.Log(TAG,
"BackgroundTaskForFindLikeMatched doInBackground likedmatchedata "
+ likedmatchedata);
Gson gson = new Gson();
matcheData = gson.fromJson(likedmatchedata,
LikedMatcheData.class);
AppLog.Log(TAG,
"BackgroundTaskForFindLikeMatched doInBackground matcheData "
+ matcheData);
if (matcheData.getErrFlag() == 0) {
likesList = matcheData.getLikes();
AppLog.Log(TAG,
"BackgroundTaskForFindLikeMatched doInBackground likesList "
+ likesList);
if (arryList != null) {
arryList.clear();
}
AppLog.Log(TAG,
"BackgroundTaskForFindLikeMatched doInBackground likesList sized "
+ likesList.size());
for (int i = 0; i < likesList.size(); i++) {
matcheddataForListview = new LikeMatcheddataForListview();
String userName = likesList.get(i).getfName();
String facebookid = likesList.get(i).getFbId();
String picturl = likesList.get(i).getpPic();
int falg = likesList.get(i).getFlag();
String latd = likesList.get(i).getLadt();
matcheddataForListview.setFacebookid(facebookid);
matcheddataForListview.setUserName(userName);
matcheddataForListview.setImageUrl(picturl);
matcheddataForListview.setFlag("" + falg);
matcheddataForListview.setladt(latd);
File imageFile = mUltilities.createFileInSideDirectory(
_picDir, userName + facebookid + ".jpg");
Utility.addBitmapToSdCardFromURL(likesList.get(i)
.getpPic().replaceAll(" ", "%20"), imageFile);
matcheddataForListview.setFilePath(imageFile
.getAbsolutePath());
if (!preferences.getString(Constant.FACEBOOK_ID, "")
.equals(facebookid)) {
arryList.add(matcheddataForListview);
}
}
DatabaseHandler mDatabaseHandler = new DatabaseHandler(
MainActivity.this);
ArrayList<LikeMatcheddataForListview> arryListtem = mDatabaseHandler
.getUserFindMatch();
AppLog.Log(TAG, "arryListtem " + arryListtem);
if (arryListtem != null && arryListtem.size() > 0) {
AppLog.Log(TAG, "arryList size " + arryListtem.size());
arryList.clear();
arryList.addAll(arryListtem);
mUltilities.showImage
}
}
// "errNum": "50",
// "errFlag": "1",
// "errMsg": "Sorry, no matches found!"
else if (matcheData.getErrFlag() == 1) {
ArrayList<LikeMatcheddataForListview> arryListtem = mDatabaseHandler
.getUserFindMatch();
AppLog.Log(TAG, "arryListtem " + arryListtem);
if (arryListtem != null && arryListtem.size() > 0) {
AppLog.Log(TAG, "arryList size " + arryListtem.size());
arryList.clear();
arryList.addAll(arryListtem);
}
} else {
}
} catch (Exception e) {
AppLog.handleException(
"BackgroundTaskForFindLikeMatched doInBackground Exception ",
e);
isResponseSuccess = false;
}
return null;
}
#Override
protected void onPostExecute(Void result) {
super.onPostExecute(result);
AppLog.Log(TAG, "BackgroundTaskForFindLikeMatched onPostExecute ");
try {
mdialog.dismiss();
} catch (Exception e) {
AppLog.Log(TAG,
"BackgroundTaskForFindLikeMatched onPostExecute Exception "
+ e);
}
if (!isResponseSuccess) {
AlertDialogManager.errorMessage(MainActivity.this, "Alert",
"Request timeout");
}
adapter.notifyDataSetChanged();
}
#Override
protected void onPreExecute() {
super.onPreExecute();
AppLog.Log(TAG, "BackgroundTaskForFindLikeMatched onPreExecute ");
try {
mdialog = mUltilities.GetProcessDialog(MainActivity.this);
mdialog.setCancelable(false);
mdialog.show();
} catch (Exception e) {
AppLog.handleException(
"BackgroundTaskForFindLikeMatched onPreExecute Exception ",
e);
}
}
}
private class MatchedDataAdapter extends
ArrayAdapter<LikeMatcheddataForListview> {
private AQuery aQuery;
private Activity mActivity;
private LayoutInflater mInflater;
private SessionManager sessionManager;
public MatchedDataAdapter(Activity context,
List<LikeMatcheddataForListview> objects,
int imageHeigthAndWidth[]) {
super(context, R.layout.matchedlistviewitem, objects);
mActivity = context;
mInflater = (LayoutInflater) mActivity
.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
// this.imageHeigthAndWidth=imageHeigthAndWidth;
sessionManager = new SessionManager(context);
aQuery = new AQuery(context);
}
#Override
public int getCount() {
return super.getCount();
}
#Override
public LikeMatcheddataForListview getItem(int position) {
return super.getItem(position);
}
#Override
public View getView(int position, View convertView, ViewGroup parent) {
ViewHolder holder;
if (convertView == null) {
holder = new ViewHolder();
convertView = mInflater.inflate(R.layout.matchedlistviewitem,
null);
holder.imageview = (ImageView) convertView
.findViewById(R.id.userimage);
holder.textview = (TextView) convertView
.findViewById(R.id.userName);
holder.lastMasage = (TextView) convertView
.findViewById(R.id.lastmessage);
convertView.setTag(holder);
} else {
holder = (ViewHolder) convertView.getTag();
}
holder.textview.setId(position);
holder.imageview.setId(position);
holder.lastMasage.setId(position);
holder.textview.setText(getItem(position).getUserName());
aQuery.id(holder.imageview).image(getItem(position).getImageUrl());
try {
holder.lastMasage.setText(sessionManager
.getLastMessage(getItem(position).getFacebookid()));
} catch (Exception e) {
AppLog.handleException(TAG + " getView Exception ", e);
}
return convertView;
}
class ViewHolder {
ImageView imageview;
TextView textview;
TextView lastMasage;
}
}
public void toggleMenu(View v) {
menu.toggle();
}
public void toggleRightMenu(View v) {
menu.showSecondaryMenu();
}
#Override
public void onBackPressed() {
if (menu.isMenuShowing()) {
menu.toggle();
} else if (menu.isSecondaryMenuShowing()) {
menu.showSecondaryMenu();
} else {
super.onBackPressed();
}
}
#Override
public void onStop() {
super.onStop();
if (mdialog != null) {
mdialog.dismiss();
mdialog = null;
}
}
#Override
protected void onDestroy() {
if (mdialog != null && mdialog.isShowing()) {
mdialog.dismiss();
}
super.onDestroy();
}
#Override
public void onClick(View v) {
FragmentManager fm = MainActivity.this.getSupportFragmentManager();
FragmentTransaction ft = fm.beginTransaction();
Fragment fragment = null;
if (v.getId() == R.id.homelayout) {
if (!cd.isConnectingToInternet()) {
Toast.makeText(this, "No Internet", Toast.LENGTH_SHORT).show();
return;
}
if (flagforHome) {
menu.toggle();
return;
} else {
fragment = new FindMatches();
buttonRightMenu
.setBackgroundResource(R.drawable.selector_for_message_button);
tvTitle.setText(getResources().getString(R.string.app_name));
flagforHome = true;
flagForProfile = false;
flagForsetting = false;
isProfileclicked = false;
if (fragment != null) {
ft.replace(R.id.activity_main_content_fragment, fragment);
ft.commit();
}
menu.toggle();
}
} else if (v.getId() == R.id.profilelayout) {
if (!cd.isConnectingToInternet()) {
Toast.makeText(this, "No Internet", Toast.LENGTH_SHORT).show();
return;
}
if (flagForProfile) {
menu.toggle();
return;
} else {
buttonRightMenu.setBackgroundResource(R.drawable.edit_btn);
isProfileclicked = true;
fragment = new UserProfile();
tvTitle.setText(getResources().getString(R.string.myprofile));
flagforHome = false;
flagForProfile = true;
flagForsetting = false;
if (fragment != null) {
ft.replace(R.id.activity_main_content_fragment, fragment);
ft.commit();
}
menu.toggle();
}
}
else if (v.getId() == R.id.settinglayout) {
if (!cd.isConnectingToInternet()) {
Toast.makeText(this, "No Internet", Toast.LENGTH_SHORT).show();
return;
}
if (flagForsetting) {
menu.toggle();
return;
} else {
buttonRightMenu
.setBackgroundResource(R.drawable.selector_for_message_button);
tvTitle.setText(getResources().getString(R.string.settings));
fragment = new SettingActivity();
flagforHome = false;
flagForProfile = false;
flagForsetting = true;
flagForInvite=false;
isProfileclicked = false;
/*if (fragment != null) {
ft.replace(R.id.activity_main_content_fragment, fragment);
ft.commit();
// tvTitle.setText(selectedItem);
}*/
menu.toggle();
/*Intent setIntent = new Intent(getApplicationContext(),Setting2.class);
startActivity(setIntent);*/
}
}
///devraj
else if (v.getId() == R.id.messages) {
if (!cd.isConnectingToInternet()) {
Toast.makeText(this, "No Internet", Toast.LENGTH_SHORT).show();
return;
}
toggleRightMenu(v);
} /*else if (v.getId() == R.id.questionLayout) {
if (!cd.isConnectingToInternet()) {
Toast.makeText(this, "No Internet", Toast.LENGTH_SHORT).show();
return;*/
/*}
menu.toggle();
Intent questionIntent = new Intent(this, QuestionsActivity.class);
startActivity(questionIntent);*/
//}
else if (v.getId() == R.id.invitelayout) {
if (!cd.isConnectingToInternet()) {
Toast.makeText(this, "No Internet", Toast.LENGTH_SHORT).show();
return;
}
// Change by Dilavar
Intent sendIntent = new Intent();
sendIntent.setAction(Intent.ACTION_SEND);
sendIntent
.putExtra(
Intent.EXTRA_TEXT,
"I am using Flamer App ! Why don't you try it out...\nInstall Flamer now !\nhttps://play.google.com/store/apps/details?id=com.appdupe.flamernofb");
sendIntent.putExtra(android.content.Intent.EXTRA_SUBJECT,
" Flamer App !");
sendIntent.setType("message/rfc822"); //
sendIntent.putExtra(android.content.Intent.EXTRA_EMAIL,
new String[] { " info#appdupe.com" });
startActivity(Intent
.createChooser(sendIntent, "Send mail using..."));
}
/*settinglayout.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View arg0) {
// TODO Auto-generated method stub
Intent mintent = new Intent(getApplicationContext(),Setting2.class);
startActivity(mintent);
}
});*/
}
}
I want Setting tab to open a new activity not fragment that is Setting2
here is my activity class that I have to open
import android.app.Activity;
import android.os.Bundle;
public class Setting2 extends Activity {
#Override
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
setContentView(R.layout.setting2);
}
}
Here is my layout , I am posting it here as it so long and don't have permission to post more lines in question.
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
>
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#088A08" >
<Button
android:id="#+id/button_menu"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_centerVertical="true"
android:layout_marginLeft="10dp"
android:background="#drawable/selector_for_menu_button"
android:onClick="toggleMenu" />
<TextView
android:id="#+id/activity_main_content_title"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_centerVertical="true"
android:text="Toker" />
<Button
android:id="#+id/button_right_menu"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_centerVertical="true"
android:layout_marginRight="10dp"
android:background="#drawable/selector_for_message_button"
android:onClick="rightmenu" />
</RelativeLayout>
<RelativeLayout
android:layout_width="fill_parent"
android:layout_height="150dp"
android:background="#088A08" >
<LinearLayout
android:id="#+id/linearLayout1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true"
android:background="#088A08" >
<ImageView
android:id="#+id/imagev1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="#drawable/btn_add_photo"
android:gravity="center_horizontal" />
</LinearLayout>
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#+id/linearLayout1"
android:layout_centerHorizontal="true"
android:layout_marginTop="22dp"
android:background="#088A08"
android:gravity="center_horizontal"
android:text="View My Profile" />
</RelativeLayout>
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:weightSum="5.0">
<RelativeLayout
android:id="#+id/lin1"
android:layout_width="fill_parent"
android:layout_weight="1.0"
android:background="#ffffff"
android:orientation="horizontal" >
<TextView
android:id="#+id/textView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignBottom="#+id/imageView1"
android:layout_alignTop="#+id/imageView1"
android:layout_marginBottom="9dp"
android:layout_marginLeft="21dp"
android:layout_toRightOf="#+id/imageView1"
android:text="Discovery Settings"
android:textSize="12dp" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignBottom="#+id/imageView1"
android:layout_alignLeft="#+id/textView1"
android:text="Change who you see" />
<ImageView
android:id="#+id/imageView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_centerVertical="true"
android:layout_marginLeft="12dp"
android:background="#drawable/pref" />
<Button
android:id="#+id/morebtn1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_alignTop="#+id/textView1"
android:layout_marginRight="20dp"
android:background="#drawable/more" />
</RelativeLayout>
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="1dp"
android:background="#color/black"
android:orientation="horizontal"/>
<RelativeLayout
android:layout_width="fill_parent"
android:layout_weight="1.0"
android:orientation="horizontal" >
<ImageView
android:id="#+id/imageView2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_centerVertical="true"
android:layout_marginLeft="12dp"
android:background="#drawable/settings" />
<TextView
android:id="#+id/textView3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignTop="#+id/imageView2"
android:layout_marginLeft="23dp"
android:layout_toRightOf="#+id/imageView2"
android:text="App Settings"
android:textSize="12dp" />
<TextView
android:id="#+id/textView2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignBottom="#+id/imageView2"
android:layout_alignLeft="#+id/textView3"
android:text="Notification and Resource" />
<Button
android:id="#+id/morebtn2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_alignTop="#+id/textView3"
android:layout_marginRight="20dp"
android:background="#drawable/more" />
</RelativeLayout>
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="1dp"
android:background="#color/black"
android:orientation="horizontal"/>
<RelativeLayout
android:layout_width="fill_parent"
android:layout_weight="1.0"
android:orientation="horizontal" >
<ImageView
android:id="#+id/imageView3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_centerVertical="true"
android:layout_marginLeft="12dp"
android:background="#drawable/filter" />
<TextView
android:id="#+id/textView4"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignBottom="#+id/imageView3"
android:layout_marginLeft="23dp"
android:layout_toRightOf="#+id/imageView3"
android:text="What are you into" />
<TextView
android:id="#+id/textView8"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignLeft="#+id/textView4"
android:layout_alignTop="#+id/imageView3"
android:text="Your Interest"
android:textSize="12dp" />
<Button
android:id="#+id/morebtn3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_alignTop="#+id/textView8"
android:layout_marginRight="20dp"
android:background="#drawable/more" />
</RelativeLayout>
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="1dp"
android:background="#color/black"
android:orientation="horizontal"/>
<RelativeLayout
android:layout_width="fill_parent"
android:layout_weight="1.0"
android:orientation="horizontal" >
<ImageView
android:id="#+id/imageView5"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_centerVertical="true"
android:layout_marginLeft="12dp"
android:background="#drawable/reachout" />
<TextView
android:id="#+id/textView6"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignBottom="#+id/imageView5"
android:layout_marginLeft="27dp"
android:layout_toRightOf="#+id/imageView5"
android:text="We want to hear it all" />
<TextView
android:id="#+id/textView7"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignLeft="#+id/textView6"
android:layout_alignTop="#+id/imageView5"
android:text="Get in Touch"
android:textSize="12dp" />
<Button
android:id="#+id/morebtn4"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_alignTop="#+id/textView7"
android:layout_marginRight="20dp"
android:background="#drawable/more" />
</RelativeLayout>
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="1dp"
android:background="#color/black"
android:orientation="horizontal"/>
<RelativeLayout
android:layout_width="fill_parent"
android:layout_weight="1.0"
android:orientation="horizontal" >
<ImageView
android:id="#+id/imageView4"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_centerVertical="true"
android:layout_marginLeft="12dp"
android:background="#drawable/share" />
<Button
android:id="#+id/morebtn5"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_alignTop="#+id/textView5"
android:layout_marginRight="20dp"
android:background="#drawable/more" />
<TextView
android:id="#+id/textView9"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignBottom="#+id/morebtn5"
android:layout_marginLeft="27dp"
android:layout_toRightOf="#+id/imageView4"
android:text="Help us spread the world" />
<TextView
android:id="#+id/textView5"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignLeft="#+id/textView9"
android:layout_alignTop="#+id/imageView4"
android:text="Tell Your Friends"
android:textSize="12dp" />
</RelativeLayout>
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="1dp"
android:background="#color/black"
android:orientation="horizontal"/>
</LinearLayout>
</LinearLayout>
Step 1
- declare your activity inside of the manifest
Step 2
- starActivity(new Intent(getAcivity(), MyClass.class));
Step 3
- post your logcat if this didn't help while it should !
Edit: the issue seems that you are not setting a height to your layouts, base on your layout that you posted you have five layouts that are missing android:layout_height please add that and force close shall be gone.

how to use shared preference on multi textview,multi checkbox,multi button and multi edit box in android?

\how use sharedpreferences on all field?
Layout XML:
<LinearLayout
android:layout_width="match_parent"
android:layout_height="75dp" >
<TextView
android:id="#+id/textView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="1." />
<CheckBox
android:id="#+id/checkBox1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="" />
<TextView
android:id="#+id/textView6"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="00:00"
android:layout_marginRight="10dp"/>
<TextView
android:id="#+id/textView11"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="00:00" />
<EditText
android:id="#+id/editText1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="www.google.co.in"
android:ems="10" >
<requestFocus />
</EditText>
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="75dp" >
<TextView
android:id="#+id/textView2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="2." />
<CheckBox
android:id="#+id/checkBox2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="" />
<TextView
android:id="#+id/textView7"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginRight="10dp"
android:text="00:00" />
<TextView
android:id="#+id/textView12"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="00:00" />
<EditText
android:id="#+id/editText2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="www.yahoo.co.in"
android:ems="10" />
</LinearLayout>
<Button
android:id="#+id/button2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_margin="10dp"
android:layout_weight="0.11"
android:text="WebView" />
</LinearLayout>
main activicty
package com.example.myproject5;
import android.app.Activity;
import android.app.Dialog;
import android.app.TimePickerDialog;
import android.content.Intent;
import android.content.SharedPreferences;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.CheckBox;
import android.widget.EditText;
import android.widget.TextView;
import android.widget.TimePicker;
public class MainActivity extends Activity {
private TextView tv6, tv7, tv11, tv12;
private EditText et1, et2;
private CheckBox cb1, cb2;
private Button submit, webview;
private int hour;
private int minute;
public static final String PREFS_NAME = "MyPrefsFile";
private static final int TIME_DIALOG_ID = 1;
private static final int TIME_DIALOG_ID1 = 2;
private static final int TIME_DIALOG_ID2 = 3;
private static final int TIME_DIALOG_ID3 = 4;
int cur = 0;
private SharedPreferences loginPreferences;
private SharedPreferences.Editor loginPrefsEditor;
private int savelogin;
#SuppressWarnings("deprecation")
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
tv6 = (TextView) findViewById(R.id.textView6);
tv7 = (TextView) findViewById(R.id.textView7);
tv11 = (TextView) findViewById(R.id.textView11);
tv12 = (TextView) findViewById(R.id.textView12);
et1 = (EditText) findViewById(R.id.editText1);
et2 = (EditText) findViewById(R.id.editText2);
cb1 = (CheckBox) findViewById(R.id.checkBox1);
cb2 = (CheckBox) findViewById(R.id.checkBox2);
submit = (Button) findViewById(R.id.button1);
webview = (Button) findViewById(R.id.button2);
tv6.setEnabled(false);
tv7.setEnabled(false);
tv11.setEnabled(false);
tv12.setEnabled(false);
et1.setEnabled(false);
et2.setEnabled(false);
loginPreferences = getSharedPreferences(PREFS_NAME, 0);
savelogin = loginPreferences.getInt("abc", 0); // save data
if (savelogin == 1) {
tv6.setText(savelogin);
} else if (savelogin == 2) {
tv7.setText(savelogin);
} else if (savelogin == 3) {
tv11.setText(0);
} else if (savelogin == 4) {
tv12.setText(0);
}
cb1.setOnClickListener(new OnClickListener() {
#Override
public void onClick(View v) {
if (cb1.isChecked()) {
tv6.setEnabled(true);
tv11.setEnabled(true);
et1.setEnabled(true);
} else {
tv6.setEnabled(false);
tv11.setEnabled(false);
et1.setEnabled(false);
}
}
});
cb2.setOnClickListener(new OnClickListener() {
#Override
public void onClick(View v) {
if (cb2.isChecked()) {
tv7.setEnabled(true);
tv12.setEnabled(true);
et2.setEnabled(true);
} else {
tv7.setEnabled(false);
tv12.setEnabled(false);
et2.setEnabled(false);
}
}
});
tv6.setOnClickListener(new OnClickListener() {
#Override
public void onClick(View v) {
showDialog(TIME_DIALOG_ID);
loadpreferences1("abc", 1);
}
});
tv7.setOnClickListener(new OnClickListener() {
#Override
public void onClick(View v) {
showDialog(TIME_DIALOG_ID1);
loadpreferences1("abc", 2);
}
});
tv11.setOnClickListener(new OnClickListener() {
#Override
public void onClick(View v) {
showDialog(TIME_DIALOG_ID2);
loadpreferences1("abc", 3);
}
});
tv12.setOnClickListener(new OnClickListener() {
#Override
public void onClick(View v) {
showDialog(TIME_DIALOG_ID3);
loadpreferences1("abc", 4);
}
});
submit.setOnClickListener(new OnClickListener() {
#Override
public void onClick(View v) {
finish();
}
});
webview.setOnClickListener(new OnClickListener() {
public void onClick(View view) {
Intent intent = new Intent(MainActivity.this, second.class);
startActivity(intent);
loadpreferences1("abc", 5);
}
});
}
protected Dialog onCreateDialog(int id) {
switch (id) {
case TIME_DIALOG_ID:
cur = TIME_DIALOG_ID;
return new TimePickerDialog(this, timePickerListener, hour, minute, true);
case TIME_DIALOG_ID1:
cur = TIME_DIALOG_ID1;
return new TimePickerDialog(this, timePickerListener, hour, minute, true);
case TIME_DIALOG_ID2:
cur = TIME_DIALOG_ID2;
return new TimePickerDialog(this, timePickerListener, hour, minute, true);
case TIME_DIALOG_ID3:
cur = TIME_DIALOG_ID3;
}
return null;
}
private TimePickerDialog.OnTimeSetListener timePickerListener = new TimePickerDialog.OnTimeSetListener() {
public void onTimeSet(TimePicker view, int selectedHour, int selectedMinute) {
hour = selectedHour;
minute = selectedMinute;
if (cur == TIME_DIALOG_ID) {
tv6.setText(new StringBuilder().append(pad(hour)).append(":").append(pad(minute)));
} else if (cur == TIME_DIALOG_ID1) {
tv7.setText(new StringBuilder().append(pad(hour)).append(":").append(pad(minute)));
} else if (cur == TIME_DIALOG_ID2) {
tv11.setText(new StringBuilder().append(pad(hour)).append(":").append(pad(minute)));
} else if (cur == TIME_DIALOG_ID3) {
tv12.setText(new StringBuilder().append(pad(hour)).append(":").append(pad(minute)));
}
}
};
private static String pad(int c) {
if (c >= 10)
return String.valueOf(c);
else
return "0" + String.valueOf(c);
}
private void loadpreferences1(String str, int in) {
loginPreferences = getSharedPreferences(PREFS_NAME, MODE_PRIVATE);
loginPrefsEditor = loginPreferences.edit();
loginPrefsEditor.putInt(str, in);
loginPrefsEditor.commit();
}
}
Use these method to save and get values from any where in your app change parameter according to your requirment
this method to save value in shared prefrences
public static void setPref(Context c, String pref, String val) {
Editor e = PreferenceManager.getDefaultSharedPreferences(c).edit();
e.putString(pref, val);
e.commit();
}
this method to get value from shared prefrences
public static String getPref(Context c, String pref, String val) {
return PreferenceManager.getDefaultSharedPreferences(c).getString(pref,
val);
}

Android custom control is this possible?

Im searching this since yesterday. I've got on many Activities some piece of code which displays user name and login. I dont want to copy and paste code in layout into every Activity, but I want something just like user controls in .NET. I've read a lot of topic about custom controls but or I don't understand it or its not possible do to this (I dont belive in that option)
Yes it is possible. Look at this sample. It is a custom Numeric Keyboard or a custom View or a custom user control. Customize it and create your own user control:
import java.util.ArrayList;
import org.mabna.order.R;
import android.app.Activity;
import android.content.Context;
import android.text.InputType;
import android.util.AttributeSet;
import android.view.LayoutInflater;
import android.view.MotionEvent;
import android.view.View;
import android.view.View.OnTouchListener;
import android.view.ViewGroup;
import android.widget.Button;
import android.widget.EditText;
import android.widget.ImageButton;
import android.widget.LinearLayout;
// this NumericKeyboard works only for EditTexts which
// have a tag with "usesNumericKeyboard" key and value of "true"
// use tag with "ignoreMeForNumericKeyboardTouchListener" key and
// value "true" for controls you do not want to set its touchListener
public class NumericKeyboard extends LinearLayout implements OnTouchListener {
private View mainView = null;
private EditText currentEditText;
private Button btn0;
private Button btn1;
private Button btn2;
private Button btn3;
private Button btn4;
private Button btn5;
private Button btn6;
private Button btn7;
private Button btn8;
private Button btn9;
private ImageButton btnBackSpace;
private ImageButton btnDeleteAll;
public NumericKeyboard(Context context) {
super(context);
}
public NumericKeyboard(Context context, AttributeSet attrs) {
super(context, attrs);
}
protected void initialize() {
LayoutInflater layoutInflater = (LayoutInflater) getContext()
.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
View view = layoutInflater
.inflate(R.layout.view_numeric_keyboard, this);
btn0 = (Button) view.findViewById(R.id.btn0);
btn1 = (Button) view.findViewById(R.id.btn1);
btn2 = (Button) view.findViewById(R.id.btn2);
btn3 = (Button) view.findViewById(R.id.btn3);
btn4 = (Button) view.findViewById(R.id.btn4);
btn5 = (Button) view.findViewById(R.id.btn5);
btn6 = (Button) view.findViewById(R.id.btn6);
btn7 = (Button) view.findViewById(R.id.btn7);
btn8 = (Button) view.findViewById(R.id.btn8);
btn9 = (Button) view.findViewById(R.id.btn9);
btnBackSpace = (ImageButton) view.findViewById(R.id.btnBackSpace);
btnDeleteAll = (ImageButton) view.findViewById(R.id.btnDeleteAll);
btn0.setOnClickListener(new OnClickListener() {
#Override
public void onClick(View v) {
editCurrentText(v, "0");
}
});
btn1.setOnClickListener(new OnClickListener() {
#Override
public void onClick(View v) {
editCurrentText(v, "1");
}
});
btn2.setOnClickListener(new OnClickListener() {
#Override
public void onClick(View v) {
editCurrentText(v, "2");
}
});
btn3.setOnClickListener(new OnClickListener() {
#Override
public void onClick(View v) {
editCurrentText(v, "3");
}
});
btn4.setOnClickListener(new OnClickListener() {
#Override
public void onClick(View v) {
editCurrentText(v, "4");
}
});
btn5.setOnClickListener(new OnClickListener() {
#Override
public void onClick(View v) {
editCurrentText(v, "5");
}
});
btn6.setOnClickListener(new OnClickListener() {
#Override
public void onClick(View v) {
editCurrentText(v, "6");
}
});
btn7.setOnClickListener(new OnClickListener() {
#Override
public void onClick(View v) {
editCurrentText(v, "7");
}
});
btn8.setOnClickListener(new OnClickListener() {
#Override
public void onClick(View v) {
editCurrentText(v, "8");
}
});
btn9.setOnClickListener(new OnClickListener() {
#Override
public void onClick(View v) {
editCurrentText(v, "9");
}
});
btnBackSpace.setOnClickListener(new OnClickListener() {
#Override
public void onClick(View v) {
editCurrentText(v, "<");
}
});
btnDeleteAll.setOnClickListener(new OnClickListener() {
#Override
public void onClick(View v) {
editCurrentText(v, "D");
}
});
if (mainView == null && !this.isInEditMode()) {
setTouchListenerForChildViews();
this.setVisibility(GONE);
}
}
protected void editCurrentText(View v, String character) {
if (currentEditText != null) {
if (character.compareTo("<") == 0) {
String text = currentEditText.getText().toString();
if (text.length() == 0) {
} else if (text.length() == 1) {
currentEditText.setText("");
} else {
text = text.substring(0, text.length() - 1);
currentEditText.setText(text);
}
} else if (character.compareTo("D") == 0) {
currentEditText.setText("");
} else {
String text = currentEditText.getText().toString();
text += character;
currentEditText.setText(text);
}
}
}
// #Override
// protected void onLayout(boolean changed, int l, int t, int r, int b) {
//
// super.onLayout(changed, l, t, r, b);
// }
public void setTouchListenerForChildViews() {
final Activity act = (Activity) getContext();
mainView = act.getWindow().getDecorView()
.findViewById(android.R.id.content);
if (mainView == null)
return;
ArrayList<View> queue = new ArrayList<View>();
queue.add((View) mainView);
while (!queue.isEmpty()) {
View v = queue.remove(0);
if (v instanceof EditText && v.getTag(R.id.usesNumericKeyboard) == Boolean
.valueOf(true)) {
((EditText) v).setInputType(InputType.TYPE_NULL);
((EditText) v).setCursorVisible(true);
v.setOnFocusChangeListener(new OnFocusChangeListener() {
#Override
public void onFocusChange(View v, boolean hasFocus) {
if (hasFocus)
{
for (NumericKeyboard numericKeyboard : arrNumericKeyboard) {
numericKeyboard.currentEditText = (EditText) v;
numericKeyboard.setVisibility(View.VISIBLE);
}
}
}
});
}
if (v instanceof NumericKeyboard) {
} else {
if (v.getTag(R.id.ignoreMeForNumericKeyboardTouchListener) != Boolean
.valueOf(true)) {
v.setOnTouchListener(this);
}
if (v instanceof ViewGroup) {
ViewGroup vg = (ViewGroup) v;
for (int i = 0; i < vg.getChildCount(); i++) {
View vChild = vg.getChildAt(i);
queue.add(vChild);
}
}
}
}
}
#Override
public boolean onTouch(View v, MotionEvent event) {
if (v instanceof EditText && v.getTag(R.id.usesNumericKeyboard) == Boolean
.valueOf(true)) {
for (NumericKeyboard numericKeyboard : arrNumericKeyboard) {
numericKeyboard.currentEditText = (EditText) v;
numericKeyboard.setVisibility(View.VISIBLE);
}
} else {
for (NumericKeyboard numericKeyboard : arrNumericKeyboard) {
numericKeyboard.setVisibility(View.GONE);
}
}
return false;
}
static ArrayList<NumericKeyboard> arrNumericKeyboard =
new ArrayList<NumericKeyboard>();
public static void registerNumericKeyboard(
NumericKeyboard numericKeyboard) {
numericKeyboard.initialize();
arrNumericKeyboard.add(numericKeyboard);
}
public static void unregisterNumericKeyboard(
NumericKeyboard numericKeyboard) {
arrNumericKeyboard.remove(numericKeyboard);
}
public static void showForEditText(EditText editText)
{
for (NumericKeyboard numericKeyboard : arrNumericKeyboard) {
numericKeyboard.setVisibility(View.VISIBLE);
numericKeyboard.currentEditText = editText;
}
}
public static void hide()
{
for (NumericKeyboard numericKeyboard : arrNumericKeyboard) {
numericKeyboard.setVisibility(View.GONE);
}
}
}
its layout as view_numeric_keyboard.xml:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="#drawable/background06"
android:orientation="vertical" >
<LinearLayout
android:id="#+id/linearLayout1"
android:layout_width="match_parent"
android:layout_height="wrap_content" >
<Button
android:id="#+id/btn7"
android:layout_width="50dip"
android:layout_height="50dip"
android:text="7" >
</Button>
<Button
android:id="#+id/btn8"
android:layout_width="50dip"
android:layout_height="50dip"
android:text="8" >
</Button>
<Button
android:id="#+id/btn9"
android:layout_width="50dip"
android:layout_height="50dip"
android:text="9" >
</Button>
</LinearLayout>
<LinearLayout
android:id="#+id/linearLayout2"
android:layout_width="match_parent"
android:layout_height="wrap_content" >
<Button
android:id="#+id/btn4"
android:layout_width="50dip"
android:layout_height="50dip"
android:text="4" >
</Button>
<Button
android:id="#+id/btn5"
android:layout_width="50dip"
android:layout_height="50dip"
android:text="5" >
</Button>
<Button
android:id="#+id/btn6"
android:layout_width="50dip"
android:layout_height="50dip"
android:text="6" >
</Button>
</LinearLayout>
<LinearLayout
android:id="#+id/linearLayout3"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal" >
<Button
android:id="#+id/btn1"
android:layout_width="50dip"
android:layout_height="50dip"
android:text="1" >
</Button>
<Button
android:id="#+id/btn2"
android:layout_width="50dip"
android:layout_height="50dip"
android:text="2" >
</Button>
<Button
android:id="#+id/btn3"
android:layout_width="50dip"
android:layout_height="50dip"
android:text="3" >
</Button>
</LinearLayout>
<LinearLayout
android:id="#+id/linearLayout4"
android:layout_width="match_parent"
android:layout_height="wrap_content" >
<ImageButton
android:id="#+id/btnBackSpace"
android:layout_width="50dip"
android:layout_height="50dip"
android:scaleType="fitCenter"
android:src="#drawable/backspace"
android:text="-" />
<Button
android:id="#+id/btn0"
android:layout_width="50dip"
android:layout_height="50dip"
android:text="0" />
<ImageButton
android:id="#+id/btnDeleteAll"
android:layout_width="50dip"
android:layout_height="50dip"
android:scaleType="fitCenter"
android:src="#drawable/remove02"
android:text="-" />
</LinearLayout>
</LinearLayout>
using it in your Activity layout:
<org.mabna.order.ui.NumericKeyboard
android:id="#+id/numericKeyboard1"
android:layout_width="wrap_content"
android:layout_height="wrap_content" >
</org.mabna.order.ui.NumericKeyboard>

Categories

Resources