Navigation Drawer -> activity para fragment - java

I'm in trouble, this code is not working.
I think my error is in the class, that has the function of the sum in class check1a4. It should be a 'Fragment'?
I tried searching in some tutorials but I did not find a solution.
MainActivity
package com.journaldev.navigationdrawer;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentManager;
import android.support.v4.widget.DrawerLayout;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.support.v7.widget.Toolbar;
import android.util.Log;
import android.view.MenuItem;
import android.view.View;
import android.widget.AdapterView;
import android.widget.ListView;
public class MainActivity extends AppCompatActivity {
private String[] mNavigationDrawerItemTitles;
private DrawerLayout mDrawerLayout;
private ListView mDrawerList;
Toolbar toolbar;
private CharSequence mDrawerTitle;
private CharSequence mTitle;
android.support.v7.app.ActionBarDrawerToggle mDrawerToggle;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
mTitle = mDrawerTitle = getTitle();
mNavigationDrawerItemTitles= getResources().getStringArray(R.array.navigation_drawer_items_array);
mDrawerLayout = (DrawerLayout) findViewById(R.id.drawer_layout);
mDrawerList = (ListView) findViewById(R.id.left_drawer);
setupToolbar();
DataModel[] drawerItem = new DataModel[3];
drawerItem[0] = new DataModel(R.drawable.connect, "Check List (1 a 4)");
drawerItem[1] = new DataModel(R.drawable.fixtures, "Check List (1 a 19)");
drawerItem[2] = new DataModel(R.drawable.table, "Sobre a sove");
getSupportActionBar().setDisplayHomeAsUpEnabled(false);
getSupportActionBar().setHomeButtonEnabled(true);
DrawerItemCustomAdapter adapter = new DrawerItemCustomAdapter(this, R.layout.list_view_item_row, drawerItem);
mDrawerList.setAdapter(adapter);
mDrawerList.setOnItemClickListener(new DrawerItemClickListener());
mDrawerLayout = (DrawerLayout) findViewById(R.id.drawer_layout);
mDrawerLayout.setDrawerListener(mDrawerToggle);
setupDrawerToggle();
}
private class DrawerItemClickListener implements ListView.OnItemClickListener {
#Override
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
selectItem(position);
}
}
private void selectItem(int position) {
Fragment fragment = null;
switch (position) {
case 0:
fragment = new ConnectFragment();
break;
case 1:
fragment = new FixturesFragment();
break;
case 2:
fragment = new TableFragment();
break;
default:
break;
}
if (fragment != null) {
FragmentManager fragmentManager = getSupportFragmentManager();
fragmentManager.beginTransaction().replace(R.id.content_frame, fragment).commit();
mDrawerList.setItemChecked(position, true);
mDrawerList.setSelection(position);
setTitle(mNavigationDrawerItemTitles[position]);
mDrawerLayout.closeDrawer(mDrawerList);
} else {
Log.e("MainActivity", "Error in creating fragment");
}
}
#Override
public boolean onOptionsItemSelected(MenuItem item) {
if (mDrawerToggle.onOptionsItemSelected(item)) {
return true;
}
return super.onOptionsItemSelected(item);
}
#Override
public void setTitle(CharSequence title) {
mTitle = title;
getSupportActionBar().setTitle(mTitle);
}
#Override
protected void onPostCreate(Bundle savedInstanceState) {
super.onPostCreate(savedInstanceState);
mDrawerToggle.syncState();
}
void setupToolbar(){
toolbar = (Toolbar) findViewById(R.id.toolbar);
setSupportActionBar(toolbar);
getSupportActionBar().setDisplayShowHomeEnabled(true);
}
void setupDrawerToggle(){
mDrawerToggle = new android.support.v7.app.ActionBarDrawerToggle(this,mDrawerLayout,toolbar,R.string.app_name, R.string.app_name);
//This is necessary to change the icon of the Drawer Toggle upon state change.
mDrawerToggle.syncState();
}
}
**java **
package com.journaldev.navigationdrawer;
import android.app.Activity;
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.EditText;
import android.app.Activity;
import android.os.Bundle;
import android.app.AlertDialog;
import android.widget.*;
import android.view.*;
public class check1a4 extends Activity {
/** Called when the activity is first created. */
CheckBox a,s,d,f,g,h,j,k,q,w,e,rr,t,y,u,i,z,x,c,v,b,n,m, aa,ss,dd,ff;
EditText resultado;
EditText hh,jj,kk,fr,qq,ww,ee;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.check1a4);
a = (CheckBox) findViewById(R.id.a);
s = (CheckBox) findViewById(R.id.s);
d = (CheckBox) findViewById(R.id.d);
f = (CheckBox) findViewById(R.id.f);
g = (CheckBox) findViewById(R.id.g);
h = (CheckBox) findViewById(R.id.h);
j = (CheckBox) findViewById(R.id.j);
k = (CheckBox) findViewById(R.id.k);
q = (CheckBox) findViewById(R.id.q);
w = (CheckBox) findViewById(R.id.w);
e = (CheckBox) findViewById(R.id.e);
t = (CheckBox) findViewById(R.id.t);
y = (CheckBox) findViewById(R.id.y);
u = (CheckBox) findViewById(R.id.u);
i = (CheckBox) findViewById(R.id.i);
z = (CheckBox) findViewById(R.id.z);
x = (CheckBox) findViewById(R.id.x);
c = (CheckBox) findViewById(R.id.c);
v = (CheckBox) findViewById(R.id.v);
b = (CheckBox) findViewById(R.id.b);
n = (CheckBox) findViewById(R.id.n);
m = (CheckBox) findViewById(R.id.m);
rr = (CheckBox) findViewById(R.id.rr);
aa = (CheckBox) findViewById(R.id.aa);
ss = (CheckBox) findViewById(R.id.ss);
dd = (CheckBox) findViewById(R.id.dd);
ff = (CheckBox) findViewById(R.id.ff);
resultado = (EditText) findViewById(R.id.total);
hh = (EditText) findViewById(R.id.hh);
jj = (EditText) findViewById(R.id.jj);
kk = (EditText) findViewById(R.id.kk);
fr = (EditText) findViewById(R.id.fr);
qq = (EditText) findViewById(R.id.qq);
ww = (EditText) findViewById(R.id.ww);
ee = (EditText) findViewById(R.id.ee);
Button bttotal = (Button) findViewById(R.id.btsomar);
bttotal.setOnClickListener(new View.OnClickListener() {
public void onClick(View arg0) {
double total = 0;
if (a.isChecked()) {
total += 10.0;
}
if (s.isChecked()) {
total += 5.00;
}
if (d.isChecked()) {
total += 5.00;
}
if (f.isChecked()) {
total += 4.00;
}
if (g.isChecked()) {
total += 1.00;
}
if (h.isChecked()) {
total += 1.00;
}
if (j.isChecked()) {
total += 1.00;
}
if (k.isChecked()) {
total += 2.00;
}
if (q.isChecked()) {
total += 1.00;
}
if (w.isChecked()) {
total += 2.00;
}
if (e.isChecked()) {
total += 2.00;
}
if (rr.isChecked()) {
total += 1.00;
}
if (t.isChecked()) {
total += 3.50;
}
if (y.isChecked()) {
total += 3.50;
}
if (u.isChecked()) {
total += 1.00;
}
if (z.isChecked()) {
total += 4.50;
}
if (x.isChecked()) {
total += 6.00;
}
if (c.isChecked()) {
total += 4.50;
}
if (v.isChecked()) {
total += 1.00;
}
if (b.isChecked()) {
total += 1.00;
}
if (z.isChecked()) {
total += 4.50;
}
if (n.isChecked()) {
total += 6.00;
}
if (m.isChecked()) {
total += 4.00;
}
if (aa.isChecked()) {
total += 1.50;
}
if (ss.isChecked()) {
total += 2.00;
}
if (dd.isChecked()) {
total += 2.50;
}
if (ff.isChecked()) {
total += 2.00;
}
double num1 = Double.parseDouble(hh.getText().toString());
double num2 = Double.parseDouble(jj.getText().toString());
double num3 = Double.parseDouble(kk.getText().toString());
double num4 = Double.parseDouble(qq.getText().toString());
double num5 = Double.parseDouble(ww.getText().toString());
double num6 = Double.parseDouble(ee.getText().toString());
double num7 = Double.parseDouble(fr.getText().toString());
////
resultado.setText(String.valueOf(num1+num2+num3+num4+num5+num6+num7+total));
}
});
}}
R.layout.check1a
<android.support.v4.widget.DrawerLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/drawer_layout"
android:layout_width="match_parent"
android:focusable="false"
android:layout_height="match_parent" >
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:focusable="false"
android:soundEffectsEnabled="false"
android:splitMotionEvents="false">
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:focusable="false"
android:addStatesFromChildren="false"
android:background="#android:color/background_light"
android:backgroundTint="#android:color/background_dark"
android:isScrollContainer="true"
android:orientation="vertical"
android:weightSum="1"
tools:isScrollContainer="true">
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="Red Lojas 1 a 4"
android:textAlignment="center"
android:textSize="18sp"
android:textStyle="bold" />
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="Disponibilidade Sua loja possui"
android:textAppearance="#style/TextAppearance.AppCompat"
android:textSize="18sp"
android:textStyle="bold" />
<CheckBox
android:id="#+id/a"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="CC 2L + CC LT 350 ML" />
<CheckBox
android:id="#+id/s"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="CC Ls 1l + CCRefPet 2L" />
<CheckBox
android:id="#+id/d"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="CC mini pet 250 ml + Ft Lar. 2l" />
<CheckBox
android:id="#+id/f"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Del valle kapo+ TP 200ml ou lt 350ml + Necta 1L + Crystal individual" />
<CheckBox
android:id="#+id/g"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="energetico" />
<CheckBox
android:id="#+id/h"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Heineken LT 350ml" />
<CheckBox
android:id="#+id/j"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Heineken LN 330 ml" />
<CheckBox
android:id="#+id/k"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Kaiser Latao Ou LT 350 ml" />
<CheckBox
android:id="#+id/q"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Sol LN" />
<TextView
android:layout_width="372dp"
android:layout_height="wrap_content"
android:editable="false"
android:text="Ativação de sua loja"
android:textAllCaps="false"
android:textAppearance="#style/TextAppearance.AppCompat"
android:textIsSelectable="false"
android:textSize="18sp"
android:textStyle="bold" />
<CheckBox
android:id="#+id/w"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Pop Externo ou entrada da loja" />
<CheckBox
android:id="#+id/e"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Pop Interno Familia" />
<CheckBox
android:id="#+id/rr"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Presença Refre Retornavel (minimo 3 frentes)" />
<CheckBox
android:id="#+id/t"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Presença Refre Retornavel gelado (minimo 3 frentes)" />
<CheckBox
android:id="#+id/y"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Rack entrada da loja de retornável" />
<CheckBox
android:id="#+id/u"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Rack de suco ou ponto entra (minimo 20 frentes)" />
<CheckBox
android:id="#+id/i"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Presença de pack fechado de cerveja na gondola" />
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="Preço correto"
android:textAppearance="#style/TextAppearance.AppCompat"
android:textSize="18sp"
android:textStyle="bold" />
<CheckBox
android:id="#+id/z"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="CC Ref Pet 2l + CC LS 1L" />
<CheckBox
android:id="#+id/x"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="CC 2l" />
<CheckBox
android:id="#+id/c"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="CC LT 350 ML" />
<CheckBox
android:id="#+id/v"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Heineken LN 330 Ml" />
<CheckBox
android:id="#+id/b"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Cerveja mainstream Lt 350 ml ou Lt 473 ml" />
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="Comunicação de preço"
android:textAppearance="#style/TextAppearance.AppCompat"
android:textSize="18sp"
android:textStyle="bold" />
<CheckBox
android:id="#+id/n"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Tudo certo maluco!"
android:textAppearance="#style/TextAppearance.AppCompat" />
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="Geladeira"
android:textAppearance="#style/TextAppearance.AppCompat"
android:textSize="18sp"
android:textStyle="bold" />
<CheckBox
android:id="#+id/m"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="1 porta com refri" />
<CheckBox
android:id="#+id/aa"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="1 porta com ncarbs" />
<CheckBox
android:id="#+id/ss"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="GDM não invadida" />
<CheckBox
android:id="#+id/dd"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Gdm 80% abastecida" />
<CheckBox
android:id="#+id/ff"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="GDM com 50% de colas" />
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="Sua Sove em loja"
android:textAppearance="#style/TextAppearance.AppCompat"
android:textSize="18sp"
android:textStyle="bold" />
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="Sovi refrigerante nota: 3.5" />
<EditText
android:id="#+id/hh"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:ems="10"
android:text="0" />
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="Sovi gelado refrigerante nota: 3.0" />
<EditText
android:id="#+id/jj"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:ems="10"
android:text="0" />
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="Sovi refrigerante individual nota:4.5" />
<EditText
android:id="#+id/kk"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:ems="10"
android:text="0" />
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="Sovi Ncarbs nota: 1.0" />
<EditText
android:id="#+id/fr"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:ems="10"
android:text="0" />
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="Sovi Gelado Ncarbs nota: 1.0" />
<EditText
android:id="#+id/qq"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:ems="10"
android:text="0" />
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="Sovi Ncarbs individual nota: 2.0" />
<EditText
android:id="#+id/ww"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:ems="10"
android:text="0" />
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="Sovi refrigerante retornavel nota: 7.0" />
<EditText
android:id="#+id/ee"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:ems="10"
android:text="0" />
<Button
android:id="#+id/btsomar"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="Verificar nota da loja" />
<EditText
android:id="#+id/total"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:ems="110"
android:inputType="textPersonName"
android:text="0" />
</LinearLayout>
</ScrollView>

Related

Rectangle Area Calculation

I am trying to calculate the rectangle area in my application. I have created a simple layout but for some reason, data is not parsed into the application. I tried to print it in the console but nothing is shown.
This is my Main Class:
package com.example.week3labcode;
import androidx.appcompat.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
public class MainActivity extends AppCompatActivity implements View.OnClickListener {
Button calcButton;
EditText number1, number2, resultFinal;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
calcButton = (Button)findViewById(R.id.button1);
number1 = (EditText) findViewById(R.id.edtext1);
number2 = (EditText) findViewById(R.id.edtext2);
resultFinal = (EditText) findViewById(R.id.edtext3);
}
#Override
public void onClick(View v){
if(v == calcButton){
number1 = (EditText) findViewById(R.id.edtext1);
number2 = (EditText) findViewById(R.id.edtext2);
double num1 = Double.parseDouble(number1.getText().toString());
double num2 = Double.parseDouble(number2.getText().toString());
calcRectangle(num1, num2);
}
}
public void calcRectangle(double x, double y){
double result = x * y;
System.out.println(result);
resultFinal = (EditText) findViewById(R.id.edtext3);
resultFinal.setText(Double.toString(result));
System.out.println('H' + result);
}
}
And the following code in my XML file that provides layout for the application:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout 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"
tools:context=".MainActivity">
<TextView
android:id="#+id/label1"
android:layout_centerHorizontal="true"
android:layout_marginVertical="20px"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Rectangle Area Calculation" />
<TextView
android:id="#+id/label2"
android:layout_below="#+id/label1"
android:layout_centerHorizontal="true"
android:layout_marginVertical="10px"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Enter Length" />
<EditText
android:id="#+id/edtext1"
android:layout_toRightOf="#+id/label2"
android:layout_centerHorizontal="true"
android:layout_alignBaseline="#+id/label2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="" />
<TextView
android:id="#+id/label3"
android:layout_below="#+id/label2"
android:layout_centerHorizontal="true"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Enter breadth" />
<EditText
android:id="#+id/edtext2"
android:layout_toRightOf="#+id/label3"
android:layout_alignBaseline="#+id/label3"
android:layout_centerHorizontal="true"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="" />
<Button
android:id="#+id/button1"
android:layout_below="#+id/label3"
android:layout_centerHorizontal="true"
android:layout_marginTop="50px"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Calculate" />
<TextView
android:id="#+id/label4"
android:layout_below="#+id/button1"
android:layout_centerHorizontal="true"
android:layout_marginVertical="20px"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Area in cm2" />
<EditText
android:id="#+id/edtext3"
android:layout_toRightOf="#+id/label4"
android:layout_centerHorizontal="true"
android:layout_alignBaseline="#+id/label4"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="" />
<Button
android:id="#+id/button2"
android:layout_below="#+id/label4"
android:layout_centerHorizontal="true"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Clear Entries" />
</RelativeLayout>
You have not set OnClickListener to your Button so calcRectangle() method is never called.
calcButton = (Button)findViewById(R.id.button1);
calcButton.setOnClickListener(new OnClickListener() {
#Override
public void onClick(View view) {
number1 = (EditText) findViewById(R.id.edtext1);
number2 = (EditText) findViewById(R.id.edtext2);
double num1 = Double.parseDouble(number1.getText().toString());
double num2 = Double.parseDouble(number2.getText().toString());
calcRectangle(num1, num2);
}
});
OR
calcButton.setOnClickListener(this);

how to use edittext inside the radiogroup in android?

**I have used four radio buttons for adding and subtraction the amount in the wallet. whenever i open the app it crashes .Whenever i open the app it crashes i don't what is error please someone help me. i am new to android. In this app i have used four radio buttons for add the amount and subtracting the amount. **
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:background="#drawable/form"
tools:context="com.sivaneshsg.wallet.MainActivity">
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="Amount"
android:textSize="25sp"
android:textStyle="italic"
android:textColor="#android:color/black"
android:paddingTop="5dp"
android:paddingBottom="10dp"
android:paddingLeft="10dp"/>
<EditText
android:id="#+id/inputamount"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="Amount in Rs."
android:paddingTop="5dp"
android:paddingBottom="10dp"
android:paddingLeft="10dp"
android:inputType="number"
android:ems="10"
/>
<RadioGroup
android:id="#+id/rgroup"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical"
android:padding="10dp"
>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Income"
android:textStyle="italic"
android:textSize="20sp"
android:textColor="#android:color/black"
android:paddingBottom="10dp"/>
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="horizontal">
<RadioButton
android:id="#+id/cash1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Cash"
android:textSize="15dp"
android:paddingRight="10dp"
android:textColor="#android:color/black"
/>
<RadioButton
android:id="#+id/card1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Card"
android:textColor="#android:color/black"
/>
</LinearLayout>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Expense"
android:textSize="20dp"
android:textStyle="italic"
android:textColor="#android:color/black"
android:paddingBottom="10dp"/>
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="horizontal">
<RadioButton
android:id="#+id/cash2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Cash"
android:textColor="#android:color/black"
android:textSize="15sp"
android:paddingRight="10dp"
/>
<RadioButton
android:id="#+id/card2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Card"
android:textSize="15sp"
android:textColor="#android:color/black"
/>
</LinearLayout>
</RadioGroup>
<Button
android:id="#+id/button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="OK"
/>
<TextView
android:id="#+id/amountcard"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textColor="#android:color/black"
android:text="Amount in Card : RS. 0"
android:textSize="25sp"
android:padding="10dp"/>
<TextView
android:id="#+id/amountcash"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Amount in Cash : Rs. 0"
android:textSize="25sp"
android:textColor="#android:color/black"
android:padding="10dp"/>
<TextView
android:id="#+id/amountwallet"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Total Amount in Wallet : RS. 0"
android:textSize="23sp"
android:textColor="#android:color/black"
android:textStyle="bold"
android:padding="10dp"/>
</LinearLayout>
package com.sivaneshsg.wallet;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.view.View;
import android.widget.Button;
import android.widget.CompoundButton;
import android.widget.EditText;
import android.widget.RadioGroup;
import android.widget.TextView;
import android.widget.Toast;
import static android.icu.lang.UCharacter.GraphemeClusterBreak.T;
public class MainActivity extends AppCompatActivity {
int cashamount = 0;
int cardamount = 0;
int totalamount;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
EditText et = (EditText) findViewById(R.id.inputamount);
final int amount = Integer.parseInt(et.getText().toString());
RadioGroup rg = (RadioGroup) findViewById(R.id.rgroup);
rg.setOnCheckedChangeListener(new RadioGroup.OnCheckedChangeListener() {
#Override
public void onCheckedChanged(RadioGroup group, int checkedId) {
if (checkedId == R.id.card1) {
cardamount = cardamount + amount;
} else if (checkedId == R.id.cash1) {
cashamount = cashamount + amount;
} else if (checkedId == R.id.cash2) {
cashamount = cashamount - amount;
} else if (checkedId == R.id.card2) {
cardamount = cardamount - amount;
}
}
});
Button button = (Button) findViewById(R.id.button);
button.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
TextView cash = (TextView) findViewById(R.id.amountcash);
TextView card = (TextView) findViewById(R.id.amountcard);
TextView wallet = (TextView) findViewById(R.id.amountwallet);
cash.setText("Amount in Cash : RS. " + cashamount);
card.setText("Amount in Card : RS. " + cardamount);
totalamount = cashamount + cashamount;
wallet.setText("Total Amount in Wallet : RS. " + totalamount);
}
});
}
}
**Whenever i open the app it crashes i don't what is error please someone help me. i am new to android. In this app i have used four radio buttons for add the amount and subtracting the amount. **
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.RadioGroup;
import android.widget.TextView;
public class teste extends AppCompatActivity {
int cashamount = 0;
int cardamount = 0;
int totalamount;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.iuiu);
EditText et = (EditText) findViewById(R.id.inputamount);
final String amount = (et.getText().toString());
RadioGroup rg = (RadioGroup) findViewById(R.id.rgroup);
rg.setOnCheckedChangeListener(new RadioGroup.OnCheckedChangeListener() {
#Override
public void onCheckedChanged(RadioGroup group, int checkedId) {
if (checkedId == R.id.card1) {
cardamount = Integer.parseInt(cardamount + amount);
} else if (checkedId == R.id.cash1) {
cashamount = Integer.parseInt(cashamount + amount);
} else if (checkedId == R.id.cash2) {
cashamount -= Integer.parseInt(amount);
} else if (checkedId == R.id.card2) {
cardamount -= Integer.parseInt(amount);
}
}
});
Button button = (Button) findViewById(R.id.button);
button.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
TextView cash = (TextView) findViewById(R.id.amountcash);
TextView card = (TextView) findViewById(R.id.amountcard);
TextView wallet = (TextView) findViewById(R.id.amountwallet);
cash.setText("Amount in Cash : RS. " + cashamount);
card.setText("Amount in Card : RS. " + cardamount);
totalamount = cashamount + cashamount;
wallet.setText("Total Amount in Wallet : RS. " + totalamount);
}
});
}
}
try the above code your problem was here
final int amount = Integer.parseInt(et.getText().toString());

Why are my views widening and then returning to normal during running of this code?

This is the code.
What more information do i need to put here?
I'm trying to find out why my text and button views are widening and then returning to normal during running of this code.
It keeps saying i need more details so i guess im just gonna talk about some nonsense here.
package com.notesquirrel.johnald.memorymagic;
import android.content.SharedPreferences;
import android.media.MediaPlayer;
import android.os.Handler;
import android.os.Message;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.view.animation.Animation;
import android.view.animation.AnimationUtils;
import android.widget.Button;
import android.widget.TextView;
import android.widget.Toast;
import java.util.Random;
public class GameActivity extends AppCompatActivity implements View.OnClickListener {
Animation wobble;
SharedPreferences prefs;
SharedPreferences.Editor editor;
String dataName = "MyData";
String intName = "MyInt";
int defaultInt = 0;
int highScore;
TextView textScore;
TextView textDifficulty;
TextView textWatchGo;
Button button1;
Button button2;
Button button3;
Button button4;
Button buttonRestart;
int difficultyLevel = 3;
int[] sequenceToCopy = new int[100];
private Handler myHandler;
boolean playSequence = false;
int elementToPlay = 0;
int playerResponses;
int playerScore;
boolean isResponding;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_game);
wobble = AnimationUtils.loadAnimation(this, R.anim.wobble);
prefs = getSharedPreferences(dataName, MODE_PRIVATE);
editor = prefs.edit();
highScore = prefs.getInt(intName, defaultInt);
final MediaPlayer powerup7 = MediaPlayer.create(this, R.raw.poweru);
final MediaPlayer powerup8 = MediaPlayer.create(this, R.raw.poweru2);
final MediaPlayer powerup9 = MediaPlayer.create(this, R.raw.poweru3);
final MediaPlayer powerup10 = MediaPlayer.create(this, R.raw.poweru4);
textScore = (TextView) findViewById(R.id.textScore);
assert textScore != null;
textScore.setText("Score: " + playerScore);
textDifficulty = (TextView) findViewById(R.id.textDifficulty);
assert textDifficulty != null;
textDifficulty.setText("Level: " + difficultyLevel);
textWatchGo = (TextView) findViewById(R.id.textWatchGo);
button1 = (Button) findViewById(R.id.button21);
button2 = (Button) findViewById(R.id.button32);
button3 = (Button) findViewById(R.id.button43);
button4 = (Button) findViewById(R.id.button54);
buttonRestart = (Button) findViewById(R.id.buttonRestart);
button1.setOnClickListener(this);
button2.setOnClickListener(this);
button3.setOnClickListener(this);
button4.setOnClickListener(this);
buttonRestart.setOnClickListener(this);
//thread
myHandler = new Handler() {
public void handleMessage(Message msg) {
super.handleMessage(msg);
if (playSequence) {
button1.setVisibility(View.VISIBLE);
button2.setVisibility(View.VISIBLE);
button3.setVisibility(View.VISIBLE);
button4.setVisibility(View.VISIBLE);
switch (sequenceToCopy[elementToPlay]) {
case 1:
// button1.setVisibility(View.INVISIBLE);
button1.startAnimation(wobble);
powerup7.start();
break;
case 2:
//button2.setVisibility(View.INVISIBLE);
button2.startAnimation(wobble);
powerup8.start();
break;
case 3:
//button3.setVisibility(View.INVISIBLE);
button3.startAnimation(wobble);
powerup9.start();
break;
case 4:
// button4.setVisibility(View.INVISIBLE);
button4.startAnimation(wobble);
powerup10.start();
break;
}
elementToPlay++;
if (elementToPlay == difficultyLevel) {
sequenceFinished();
}
}
myHandler.sendEmptyMessageDelayed(0, 900);
}
};
myHandler.sendEmptyMessage(0);
playASequence();
}
#Override
public void onClick(View v) {
final MediaPlayer powerup7 = MediaPlayer.create(this, R.raw.poweru);
final MediaPlayer powerup8 = MediaPlayer.create(this, R.raw.poweru2);
final MediaPlayer powerup9 = MediaPlayer.create(this, R.raw.poweru3);
final MediaPlayer powerup10 = MediaPlayer.create(this, R.raw.poweru4);
if (!playSequence) {
switch (v.getId()) {
case R.id.button21:
powerup7.start();
checkElement(1);
break;
case R.id.button32:
powerup8.start();
checkElement(2);
break;
case R.id.button43:
powerup9.start();
checkElement(3);
break;
case R.id.button54:
powerup10.start();
checkElement(4);
break;
case R.id.buttonRestart:
difficultyLevel = 3;
playerScore = 0;
textScore.setText("Score: " + playerScore);
playASequence();
break;
}
}
}
public void createSequence() {
//For choosing a random button
Random randInt = new Random();
int ourRandom;
for (int i = 0; i < difficultyLevel; i++) {
//get a random number between 1 and 4
ourRandom = randInt.nextInt(4);
ourRandom++;//make sure it is not zero
//Save that number to our array
sequenceToCopy[i] = ourRandom;
}
}
public void playASequence() {
createSequence();
isResponding = false;
elementToPlay = 0;
playerResponses = 0;
textWatchGo.setText("WATCH!");
playSequence = true;
}
public void sequenceFinished() {
playSequence = false;
//make sure all the buttons are made visible
// button1.setVisibility(View.VISIBLE);
// button2.setVisibility(View.VISIBLE);
// button3.setVisibility(View.VISIBLE);
// button4.setVisibility(View.VISIBLE);
textWatchGo.setText("GO!");
isResponding = true;
}
public void checkElement(int thisElement) {
if (isResponding) {
playerResponses++;
if (sequenceToCopy[playerResponses - 1] == thisElement) {//Correct
playerScore = playerScore + ((thisElement + 1) * 2);
textScore.setText("Score: " + playerScore);
if (playerResponses == difficultyLevel) {//got the whole sequence
//don't checkElelment anymore
isResponding = false;
//now raise the difficulty
difficultyLevel++;
//and play another sequence
playASequence();
}
} else {//wrong answer
textWatchGo.setText("FAILED!");
//don't checkElelment anymore
isResponding = false;
if (playerScore > highScore) {
highScore = playerScore;
editor.putInt(intName, highScore);
editor.commit();
Toast.makeText(getApplicationContext(), "New high score!!", Toast.LENGTH_LONG).show();
}
}
}
}
}
XML layout:
<?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: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="com.notesquirrel.johnald.memorymagic.GameActivity"
android:background="#000000">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceLarge"
android:text="Score: 999"
android:textSize="40sp"
android:id="#+id/textScore"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceLarge"
android:text="Difficulty: 4"
android:textSize="25sp"
android:id="#+id/textDifficulty"
android:layout_below="#+id/textScore"
android:layout_centerHorizontal="true" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceLarge"
android:text="Watch/Go"
android:id="#+id/textWatchGo"
android:layout_marginTop="48dp"
android:textSize="25sp"
android:layout_below="#+id/textDifficulty"
android:layout_centerHorizontal="true" />
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="1"
android:id="#+id/button21"
android:layout_marginTop="50dp"
android:layout_below="#+id/textWatchGo"
android:layout_alignRight="#+id/textScore"
android:layout_alignEnd="#+id/textScore"
android:layout_alignLeft="#+id/textScore"
android:layout_alignStart="#+id/textScore" />
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="2"
android:id="#+id/button32"
android:layout_marginTop="10dp"
android:layout_below="#+id/button21"
android:layout_alignRight="#+id/button21"
android:layout_alignEnd="#+id/button21"
android:layout_alignLeft="#+id/button21"
android:layout_alignStart="#+id/button21" />
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="3"
android:layout_marginTop="10dp"
android:id="#+id/button43"
android:layout_below="#+id/button32"
android:layout_alignRight="#+id/button32"
android:layout_alignEnd="#+id/button32"
android:layout_alignLeft="#+id/button32"
android:layout_alignStart="#+id/button32" />
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="4"
android:layout_marginTop="10dp"
android:id="#+id/button54"
android:layout_below="#+id/button43"
android:layout_alignRight="#+id/button43"
android:layout_alignEnd="#+id/button43"
android:layout_alignLeft="#+id/button43"
android:layout_alignStart="#+id/button43" />
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Restart"
android:id="#+id/buttonRestart"
android:layout_marginTop="10dp"
android:layout_alignParentBottom="true"
android:layout_alignParentRight="true"
android:layout_alignParentEnd="true" />
</RelativeLayout>
I have no problem with my device. But I removed some constraints.
<?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: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="com.notesquirrel.johnald.memorymagic.GameActivity"
android:background="#000000">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceLarge"
android:text="Score: 999"
android:textSize="40sp"
android:id="#+id/textScore"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceLarge"
android:text="Difficulty: 4"
android:textSize="25sp"
android:id="#+id/textDifficulty"
android:layout_below="#+id/textScore"
android:layout_centerHorizontal="true" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceLarge"
android:text="Watch/Go"
android:id="#+id/textWatchGo"
android:layout_marginTop="48dp"
android:textSize="25sp"
android:layout_below="#+id/textDifficulty"
android:layout_centerHorizontal="true" />
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="1"
android:id="#+id/button21"
android:layout_marginTop="50dp"
android:layout_below="#+id/textWatchGo"
android:layout_alignRight="#+id/textScore"
android:layout_alignLeft="#+id/textScore"
/>
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="2"
android:id="#+id/button32"
android:layout_marginTop="10dp"
android:layout_below="#+id/button21"
android:layout_alignRight="#+id/button21"
android:layout_alignLeft="#+id/button21"
/>
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="3"
android:layout_marginTop="10dp"
android:id="#+id/button43"
android:layout_below="#+id/button32"
android:layout_alignRight="#+id/button32"
android:layout_alignLeft="#+id/button32"
/>
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="4"
android:layout_marginTop="10dp"
android:id="#+id/button54"
android:layout_below="#+id/button43"
android:layout_alignRight="#+id/button43"
android:layout_alignLeft="#+id/button43"
/>
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Restart"
android:id="#+id/buttonRestart"
android:layout_marginTop="10dp"
android:layout_alignParentBottom="true"
android:layout_alignParentRight="true"
/>
</RelativeLayout>

Android studio, android scrolling down and up enable

I want to add something like scrolling from top to bottom and vice versa but i don't know how to add this function, i was trying with ScrollView but that gave nothing.
MainActivity.java :
package com.example.marek.przelicznikpaliw;
import android.support.v7.app.ActionBarActivity;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.widget.EditText;
import android.widget.TextView;
import android.widget.Toast;
public class MainActivity extends ActionBarActivity {
private EditText a1;
private EditText b1;
private EditText c1;
private EditText d1;
private TextView tv;
private TextView tv2;
private TextView tv3;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
//pola
a1 = (EditText) findViewById(R.id.cel);
b1 = (EditText) findViewById(R.id.pali);
c1 = (EditText) findViewById(R.id.litr);
d1 = (EditText) findViewById(R.id.koszt);
// wynik
tv = (TextView) findViewById(R.id.wynikKoszt);
tv2 = (TextView) findViewById(R.id.wynikKilometry);
tv3 = (TextView) findViewById(R.id.wynikKosztx2);
findViewById(R.id.button).setOnClickListener(onClickListener);
findViewById(R.id.button2).setOnClickListener(onClickListener);
}
private View.OnClickListener onClickListener = new View.OnClickListener() {
#Override
public void onClick(View view) {
float a = 0;
float b = 0;
float c = 0;
float d = 0;
float wynik = 0;
float wynik2 = 0;
float wynik3 = 0;
try {
a = Float.parseFloat(a1.getText().toString());
b = Float.parseFloat(b1.getText().toString());
c = Float.parseFloat(c1.getText().toString());
d = Float.parseFloat(d1.getText().toString());
} catch (Exception e) {
e.printStackTrace();
}
if (view.getId() == R.id.button) {
wynik = ((b / 100) * a) * c;
tv.setText(String.valueOf(wynik));
wynik2 = (((b / 100) * a) * c)*2;
tv3.setText(String.valueOf(wynik2));
} else if (view.getId() == R.id.button2) {
wynik3 = d / ((b * c) / 100);
tv2.setText(String.valueOf(wynik3));
}
}
};
}
activity_main.xml :
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent"
android:layout_height="match_parent" android:paddingLeft="#dimen/activity_horizontal_margin"
android:paddingRight="#dimen/activity_horizontal_margin"
android:paddingTop="#dimen/activity_vertical_margin"
android:paddingBottom="#dimen/activity_vertical_margin" tools:context=".MainActivity"
android:orientation="vertical"
android:onClick="onButtonClick"
android:weightSum="1">
<EditText
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/cel"
android:hint="Ilosc km do celu to:"
android:layout_centerHorizontal="true"
android:numeric="integer|decimal" />
<EditText
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/pali"
android:hint="Ile litrow pali na 100km"
android:layout_centerHorizontal="true"
android:layout_below="#+id/cel"
android:numeric="integer|decimal" />
<EditText
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/litr"
android:hint="Cena za litr"
android:layout_below="#+id/pali"
android:layout_centerHorizontal="true"
android:numeric="integer|decimal" />
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/button"
android:layout_below="#+id/litr"
android:layout_centerHorizontal="true"
android:hint="Licz zlotowki"
android:text="Licz koszty"
android:clickable="true" />
<EditText
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/koszt"
android:layout_centerVertical="true"
android:layout_centerHorizontal="true"
android:hint="Za ile zl zostalo zatankowane gaz/paliwo?"
android:numeric="integer|decimal" />
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Licz kilometry"
android:id="#+id/button2"
android:layout_below="#+id/koszt"
android:layout_centerHorizontal="true"
android:clickable="true" />
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceLarge"
android:text="Dojedziesz w wybrany cel za(zł):"
android:id="#+id/textView" />
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceLarge"
android:text="#string/emptystring"
android:id="#+id/wynikKoszt"
android:textIsSelectable="false" />
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceLarge"
android:text="Oraz spowrotem za(zł):"
android:id="#+id/textView2" />
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="#string/emptystring"
android:id="#+id/wynikKosztx2"
android:layout_weight="0.06" />
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceLarge"
android:text="Za tę kwotę przejedziesz(km):"
android:id="#+id/textView3" />
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceLarge"
android:text="#string/emptystring"
android:id="#+id/wynikKilometry" />

android cannot be resolved or is not a field error

I created a tictactoe android game, and when i try to link the strings.xml file to activity.java I receive an error.
Here is my activity.java
package com.tictactoeoyna.www;
import android.R;
import android.app.Activity;
import android.graphics.Color;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;
public class TicTacToeOynaActivity extends Activity {
private TicTacToeOyun mGame;
private Button mBoardButtons[];
private TextView mInfoTextView;
private TextView mHumanCount;
private TextView mTieCount;
private TextView mAndroidCount;
private int mHumanCounter = 0;
private int mTieCounter = 0;
private int mAndroidCounter = 0;
private boolean mHumanFirst = true;
private boolean mGameOver = false;
/** Called when the activity is first created. */
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
mBoardButtons = new Button[TicTacToeOyun.getBOARD_SIZE()];
mBoardButtons[0] = (Button) findViewById(R.id.one);// it should be blue but not
mBoardButtons[1] = (Button) findViewById(R.id.two);//same
mBoardButtons[2] = (Button) findViewById(R.id.three);
mBoardButtons[3] = (Button) findViewById(R.id.four);
mBoardButtons[4] = (Button) findViewById(R.id.five);
mBoardButtons[5] = (Button) findViewById(R.id.six);
mBoardButtons[6] = (Button) findViewById(R.id.seven);
mBoardButtons[7] = (Button) findViewById(R.id.eight);
mBoardButtons[8] = (Button) findViewById(R.id.nine);//until here
mInfoTextView = (TextView) findViewById(R.id.information);
mHumanCount = (TextView) findViewById(R.id.humanCount);
mTieCount = (TextView) findViewById(R.id.tiesCount);
mAndroidCount = (TextView) findViewById(R.id.androidCount);
mHumanCount.setText(Integer.toString(mHumanCounter));
mTieCount.setText(Integer.toString(mTieCounter));
mAndroidCount.setText(Integer.toString(mAndroidCounter));
mGame = new TicTacToeOyun();
startNewGame();
}
private void startNewGame()
{
mGame.clearBoard();
for (int i = 0; i < mBoardButtons.length; i++)
{
mBoardButtons[i].setText("");
mBoardButtons[i].setEnabled(true);
mBoardButtons[i].setOnClickListener(new ButtonClickListener(i));
}
if (mHumanFirst)
{
mInfoTextView.setText(R.string.first_human);
mHumanFirst = false;
}
else
{
mInfoTextView.setText(R.string.turn_computer);
int move = mGame.getComputerMove();
setMove(mGame.ANDROID_PLAYER, move);
mHumanFirst = true;
}
}
private class ButtonClickListener implements View.OnClickListener
{
int location;
public ButtonClickListener(int location)
{
this.location = location;
}
public void onClick(View view)
{
if (!mGameOver)
{
if (mBoardButtons[location].isEnabled())
{
setMove(mGame.HUMAN_PLAYER, location);
int winner = mGame.checkForWinner();
if (winner == 0)
{
mInfoTextView.setText(R.string.turn_computer);
int move = mGame.getComputerMove();
setMove(mGame.ANDROID_PLAYER, move);
winner = mGame.checkForWinner();
}
if (winner == 0)
mInfoTextView.setText(R.string.turn_human);
else if (winner == 1)
{
mInfoTextView.setText(R.string.result_tie);
mTieCounter++;
mTieCount.setText(Integer.toString(mTieCounter));
mGameOver = true;
}
else if (winner == 2)
{
mInfoTextView.setText(R.string.result_human_wins);
mHumanCounter++;
mHumanCount.setText(Integer.toString(mHumanCounter));
mGameOver = true;
}
else
{
mInfoTextView.setText(R.string.result_android_wins);
mAndroidCounter++;
mAndroidCount.setText(Integer.toString(mAndroidCounter));
mGameOver = true;
}
}
}
}
}
private void setMove(char player, int location)
{
mGame.setMove(player, location);
mBoardButtons[location].setEnabled(false);
mBoardButtons[location].setText(String.valueOf(player));
if (player == mGame.HUMAN_PLAYER)
mBoardButtons[location].setTextColor(Color.GREEN);
else
mBoardButtons[location].setTextColor(Color.RED);
}
}
The error is on one, two, three...nine and information count, human count etc. Here is my fragment file, so why can't I see one, two, three....nine labeled blue? Why is it not recognized? What have I done wrong ? I received the errors after findviewbyid.
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" >
<TableLayout
android:id="#+id/playArea"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="10dp" >
<TableRow
android:id="#+id/tableRow1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="center_horizontal" >
<Button
android:id="one"
android:layout_width="100dp"
android:layout_height="100dp"
android:text="#string/one"
android:textSize="70dp" />
<Button
android:id="#+id/two"
android:layout_width="100dp"
android:layout_height="100dp"
android:text="#string/two"
android:textSize="70dp" />
<Button
android:id="#+id/three"
android:layout_width="100dp"
android:layout_height="100dp"
android:text="#string/three"
android:textSize="70dp" />
</TableRow>
<TableRow
android:id="#+id/tableRow2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="center_horizontal" >
<Button
android:id="#+id/four"
android:layout_width="100dp"
android:layout_height="100dp"
android:text="#string/four"
android:textSize="70dp" />
<Button
android:id="#+id/five"
android:layout_width="100dp"
android:layout_height="100dp"
android:text="#string/five"
android:textSize="70dp" />
<Button
android:id="#+id/six"
android:layout_width="100dp"
android:layout_height="100dp"
android:text="#string/six"
android:textSize="70dp" />
</TableRow>
<TableRow
android:id="#+id/tableRow3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="center_horizontal" >
<Button
android:id="#+id/seven"
android:layout_width="100dp"
android:layout_height="100dp"
android:text="#string/seven"
android:textSize="70dp" />
<Button
android:id="#+id/eight"
android:layout_width="100dp"
android:layout_height="100dp"
android:text="#string/eight"
android:textSize="70dp" />
<Button
android:id="#+id/nine"
android:layout_width="100dp"
android:layout_height="100dp"
android:text="#string/nine"
android:textSize="70dp" />
</TableRow>
</TableLayout>
<TextView
android:id="#+id/information"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="5dp"
android:gravity="center_horizontal"
android:text="#string/info"
android:textSize="25dp" />
<TableLayout
android:id="#+id/tableLayout1"
android:layout_width="match_parent"
android:layout_height="wrap_content" >
<TableRow
android:id="#+id/tableRow4"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="10dp"
android:gravity="center_horizontal" >
<TextView
android:id="#+id/human"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/human" />
<TextView
android:id="#+id/humanCount"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginRight="10dp" />
<TextView
android:id="#+id/ties"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/ties" />
<TextView
android:id="#+id/tiesCount"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginRight="10dp" />
<TextView
android:id="#+id/android"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/android" />
<TextView
android:id="#+id/androidCount"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
</TableRow>
</TableLayout>
</LinearLayout>
import com.tictactoeoyna.www.R;
and removeimport android.R;
When you got this type of error at anywhere and you have import android.R; then just remove import android.R;.

Categories