I'm developing an android application which stores words given by the user in a SQLite database. And I want to retrieve those words as radio buttons so that the user can select only one word from the words list show in the textview.
And I want to create the xml file to fulfill that requirement.
Help me with this and thanks in advance.
*
<?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"
tools:context=".EditPhrase">
<TextView
android:id="#+id/editText"
android:layout_width="355dp"
android:layout_height="71dp"
android:layout_marginStart="8dp"
android:layout_marginLeft="8dp"
android:layout_marginTop="28dp"
android:layout_marginEnd="8dp"
android:layout_marginRight="8dp"
android:text="#string/edit_phrases"
android:textColor="#000000"
android:textSize="30sp"
/>
<ScrollView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#+id/editText">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<RadioGroup
android:layout_width="400dp"
android:layout_height="wrap_content">
<TextView
android:id="#+id/phraseView"
android:layout_width="400dp"
android:layout_height="wrap_content"
android:autoLink="web"
android:lineSpacingExtra="#dimen/line_spacing"
android:padding="#dimen/padding_regular"
android:text="" />
</LinearLayout>
</ScrollView>
</RelativeLayout>
*
P.S. - "phraseView" textview is used to show the retrieved data from sqlite database and it works and all the words are printed one by one.
Now I want to have a radio button in-front of every word so that the user can select only one word
*
public class EditPhrase extends AppCompatActivity {
TextView textView;
DatabaseHelper translateDB;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_edit_phrase);
textView = findViewById(R.id.phraseView);
translateDB = new DatabaseHelper(this);
showData();
}
public void showData(){
Cursor cursor = translateDB.retrieveData();
System.out.println("1");
if (cursor.getCount() == 0){
Toast.makeText(EditPhrase.this, "No data", Toast.LENGTH_LONG).show();
return;
}
StringBuffer buffer = new StringBuffer();
System.out.println("2");
while (cursor.moveToNext()) {
System.out.println("3");
buffer.append(" " + cursor.getString(0) + "\n");
}
textView.setText(buffer.toString());
}
}
*
Try putting the radio buttons inside a RecyclerView or ListView which is inside a RadioGroup
Related
How to get value from dynamically created EditText in Android?
This is my dynamic view (XML file)
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<EditText
android:id="#+id/et_waypoint"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:background="#drawable/background"
android:hint="Way Points"
android:padding="10dp"
android:textSize="16sp" />
<Button
android:id="#+id/btn_waypoint"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Find" />
</LinearLayout>
And I am using LayoutInflater because I want perfect Designed layout which is not accomplish by me via setLayoutParams so this is the reason I am using LayoutInflater.
And here is my code:
LayoutInflater l = getLayoutInflater();
final LinearLayout mainActivity = (LinearLayout) findViewById(R.id.dynamic);
final View view = l.inflate(R.layout.dynamic_layout_waypoints, null);
buttonWayPoints = (Button) view.findViewById(R.id.btn_waypoint);
editTextWayPoints = (EditText) view.findViewById(R.id.et_waypoint);
mainActivity.addView(editTextWayPoints);
I am new to Android. Most of people suggest this solution but it's not worked for me, the issue is when I implement this code my ADD NEW EDIT TEXT BUTTON not respond me.
This is how I am trying to get inserted value but it returns value of only last created edit text:
public Cursor getPerson(String Query) {
SQLiteDatabase db = this.getReadableDatabase();
Cursor c = db.rawQuery(Query, null);
return c;
}
sb is StringBuilder sb;, w is String w;
String queryWayPoints = "select * from route_table where trip_id = " + t;
Cursor s = myDb.getPerson(queryWayPoints);
int count3 = s.getCount();
for (int j = 0; j < count3; j++) {
s.moveToNext();
w = s.getString(s.getColumnIndex("waypoints"));
// se.append(w + "." + "00");
}
trip_name.setText(n);
trip_date.setText(d);
sb.append(w);
}
trip_route.setText(sb.toString());
Although, I didn't get what exactly your question is, still I'll try to help.
What exactly this code does is, on clicking the button on top an new layout(one that you wanted) will add to the activity screen at runtime, i.e an edittext with a button, and when you click on that button, A toast with the value of respective edittext will be shown. Hence solving the problem of getting the value of dynamically added edittext
MainActivity
public class MainActivity extends AppCompatActivity {
Button generateET;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
final LinearLayout myLinearLay = (LinearLayout) findViewById(R.id.dynamic);
generateET = (Button) findViewById(R.id.generateBtn);
generateET.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View view) {
LayoutInflater l = getLayoutInflater();
final View viewToAdd = l.inflate(R.layout.to_add, null);
Button buttonWayPoints = (Button) viewToAdd.findViewById(R.id.btn_waypoint);
final EditText editTextWayPoints = (EditText) viewToAdd.findViewById(R.id.et_waypoint);
buttonWayPoints.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View view) {
if (editTextWayPoints.getText().toString() != null) {
Toast.makeText(MainActivity.this, editTextWayPoints.getText().toString(), Toast.LENGTH_SHORT).show();
} else {
Toast.makeText(MainActivity.this, "No text found", Toast.LENGTH_SHORT).show();
}
}
});
myLinearLay.addView(viewToAdd);
}
});
}
}
activity_main.xml
<?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="com.techmahindra.stackques.MainActivity">
<Button
android:id="#+id/generateBtn"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:text="add editText To layout" />
<ScrollView
android:layout_below="#+id/generateBtn"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:fillViewport="true">
<LinearLayout
android:id="#+id/dynamic"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
></LinearLayout>
</ScrollView>
</RelativeLayout>
to_add.xml(layout which will be inflated at runtime)
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<EditText
android:id="#+id/et_waypoint"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:hint="Way Points"
android:padding="10dp"
android:textSize="16sp" />
<Button
android:id="#+id/btn_waypoint"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Find" />
</LinearLayout>
There are some problems with your code. You're trying to add editTextWayPoints to mainActivity, but editTextWayPoints already has a parent, which is view. I think you should be adding view to mainActivity (mainActivity.addView(view)). Finally, to access the value of editTextWayPoints, you simply do editTextWayPoints.getText().toString();
i am newbie in android and i am trying to use two spinner views in an activity. entries are showing in drop down of spinner but when i select an entry, it doesn't appear in spinner control. I have searched all over but it didn't work for me. following is all i am doing/trying.
My activity xml is as
<?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_seventy_thirty"
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.elecsysindia.montestapp.SeventyThirtyActivity">
<TextView
android:text="Division"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/txtDivison"
android:textSize="20sp"
android:layout_alignParentTop="true"
android:layout_marginTop="16dp"
android:layout_marginRight="16dp"
/>
<Spinner
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="#+id/spinnerDivision"
android:layout_marginLeft="32dp"
android:layout_alignTop="#+id/txtDivison"
android:layout_toRightOf="#+id/txtDivison"
android:layout_toEndOf="#+id/txtDivison" />
<TextView
android:text="Station"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#+id/txtDivison"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:layout_marginTop="16dp"
android:layout_marginRight="16dp"
android:id="#+id/txtStationCode"
android:textSize="20sp"
/>
<Spinner
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="#+id/spinnerStation"
android:layout_below="#+id/spinnerDivision"
android:layout_alignLeft="#+id/spinnerDivision"
android:layout_alignStart="#+id/spinnerDivision"
android:layout_marginTop="16dp"
android:layout_marginStart="48dp"
android:layout_marginBottom="16dp"
android:layout_marginLeft="48dp" />
<Button
android:text="Submit"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/btnSubmit"
android:layout_marginLeft="16dp"
android:layout_marginTop="16dp"
android:layout_alignLeft="#+id/spinnerStation"
android:layout_below="#+id/spinnerStation"
/>
</RelativeLayout>
and in class:
private static List<String> listDivisions = new ArrayList<String>();
private List<String> listStation = new ArrayList<>();
Spinner spinnerDivision ;
Spinner spinnerStation;
Button btnSubmit;
ArrayAdapter<String> adapterDivision;
ArrayAdapter<String> adapterStation;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_seventy_thirty);
spinnerDivision = (Spinner) findViewById(R.id.spinnerDivision);
spinnerStation = (Spinner) findViewById(R.id.spinnerStation);
btnSubmit = (Button) findViewById(R.id.btnSubmit);
// adapterDivision = new ArrayAdapter<String>(this,android.R.layout.simple_spinner_item,listDivisions);
adapterDivision = new ArrayAdapter<String>(getApplicationContext(),R.layout.layout_spinner_item,listDivisions);
adapterDivision.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
spinnerDivision.setAdapter(adapterDivision);
adapterDivision.notifyDataSetChanged();
adapterStation = new ArrayAdapter<String>(getApplicationContext(), android.R.layout.simple_spinner_item,listStation);
adapterStation.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
spinnerStation.setAdapter(adapterStation);
adapterStation.notifyDataSetChanged();
And this is how lists are updated:
for (int i = 0; i < subs.length(); i++){
JSONObject subsDetail = subs.getJSONObject(i);
ArrayList<String> stnList = new ArrayList<String>();
if(subsDetail != null){
stnList.clear();
String DivCode = subsDetail.getString("divCode");
JSONArray st = subsDetail.getJSONArray("stncode");
String city="";
for (int j=0 ; j<st.length(); j++){
stnList.add(st.getString(j));
city = city.concat(st.getString(j)+"-");
}
mapSubscriptions.put(DivCode,stnList);
listDivisions.add(DivCode);
listStation.addAll(stnList);
I am getting data from simple php script and this data is getting inserted to lists.
Also after searching related issue in Sof, i have tried to use a separate layout for spinner as used in
adapterDivision = new ArrayAdapter<String>(getApplicationContext(),R.layout.layout_spinner_item,listDivisions);
but still of no use.
xml file for layout_spinner_item is as follows:
<?xml version="1.0" encoding="utf-8"?>
<TextView
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="#+id/spinnerItem"
android:textSize="20sp"
android:gravity="left"
android:textColor="#aaddaa"
android:padding="5dip"
/>
I even tried to make text color change in theme itself by setting property android:textColor. but again no success.
<item name="android:textColor">#FF00FF</item>
can you please help me why text is not appearing in spinner control.
After a lot of struggle, text in one spinner is appearing but that appears only if i restart activity directly , i mean without navigating to activity from main activity.
second spinner (spinnerStation) dont show the text at all. even same source code for both spinners. please see screen shots.
text appear in spinnerDivision
Entries of spinnerStation which dont show text
You have to programmatically select the position.
Like this
spinnerObject.setSelection(INDEX);
And, you should change this
adapterDivision = new ArrayAdapter<String>(getApplicationContext(),R.layout.layout_spinner_item,listDivisions);
to this,
adapterDivision = new ArrayAdapter<String>(getApplicationContext(),android.R.layout.simple_spinner_dropdown_item,listDivisions);
The problem is, your adapter is not getting TextView from custom layout file
I want to display the data from content provider in gridview more than 3 sub items or line
here is my java source code
#Override
public void onLoadFinished(Loader<Cursor> arg0, Cursor cursor) {
players.clear();
// First Check if cursor is not null
if(cursor != null ) {
StringBuilder result = new StringBuilder();
// Now loop to all items and append it to string builder
while (cursor.moveToNext()) {
String id = cursor.getString(cursor.getColumnIndex("ID"));
String name = cursor.getString(cursor.getColumnIndex("ITEM_NAME"));
String qty = cursor.getString(cursor.getColumnIndex("QUANTITY"));
String inst = cursor.getString(cursor.getColumnIndex("INSTRUCTION"));
String pid = cursor.getString(cursor.getColumnIndex("POS_ID"));
players.add("Items :" + name + "\n" + "Qty :" + qty + "\n" +
"Details :" + inst + "\n" + " Pos ID :" + pid);
gv.setAdapter(adapter);
resultView.setText(result);
}
} else {
// If cursor is null then display toast amd set empty data.
resultView.setText("Empty data");
Toast.makeText(MainActivity.this, "May be there is no app corresponding to your provider or there is null data.",
Toast.LENGTH_LONG).show();
}
}
the gv.setAdapter(adapter) is where i display the data coming from the content provider
and here is my xml source code
<?xml version="1.0" encoding="utf-8"?>
<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:background="#ffffff"
android:fillViewport="true"
tools:context="com.condorpos.kitchen_bumpbar.MainActivity">
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:padding="5dp">
<Button
android:id="#+id/btnRetrieve"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_margin="5dp"
android:padding="5dp"
android:text="#string/show_data" />
<TextView
android:id="#+id/result"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_margin="5dp"
android:clickable="false"
android:padding="5dp"
android:textColor="#000000"
android:textSize="15sp" />
<GridView
android:layout_width="match_parent"
android:layout_height="420dp"
android:numColumns="5"
android:verticalSpacing="140dp"
android:id="#+id/gridView1"/>
<android.support.v7.widget.RecyclerView
android:id="#+id/expListView"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1"
android:visibility="invisible" />
<TextView
android:id="#+id/empty_view"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="center"
android:visibility="gone"
android:text="#string/empty_list"
android:layout_marginLeft="8dp"
android:layout_marginRight="8dp"/>
</LinearLayout>
</LinearLayout>
the gridView1 is equals to gv on the java source code i declare it like
Griview gv;
gv=(GridView) findViewById(R.id.gridView1);
from the image below it shows that the data is not fully display looked per column i want to display more than 3 lines but it gives me this result
Any idea or help will do
Thanks a lot guys
You need make height of GridView is match_parent/wrap_content (based on your layout), don't fix size 420dp
Developing an android app here I am dynamically generating EditText and button like Call and Remove from row.xml file. adding these control to LinearLayout I implemented as I want but my problem is that I want to save the EditText values into xml file. so that next time I open this app the particular values gets populated from xml file.
Adding name and Mobile number to TextBox and click on "Add" button these values are dynamically added to LinearLayout. when I click on Add this values are stored into xml file and whenever next time I launch the app stored xml values are populated into LinearLayout.
this is my code
public class MainActivity : Activity
{
int count = 1;
EditText textIn, txtPhoneNo;
Button buttonAdd;
LinearLayout container;
EditText textOut;
System.Collections.ArrayList arrList = new System.Collections.ArrayList();
protected override void OnCreate(Bundle bundle)
{
base.OnCreate(bundle);
SetContentView(Resource.Layout.Main);
textIn = (EditText)FindViewById(Resource.Id.textin);
txtPhoneNo = (EditText)FindViewById(Resource.Id.txtPhoneNo);
buttonAdd = (Button)FindViewById(Resource.Id.add);
container = (LinearLayout)FindViewById(Resource.Id.container);
}
private void buttonAdd_Click(object sender, EventArgs e)
{
LayoutInflater layoutInflater = Application.Context.GetSystemService(Context.LayoutInflaterService) as LayoutInflater;
View addView = layoutInflater.Inflate(Resource.Layout.row, null);
textOut = (EditText)addView.FindViewById(Resource.Id.textout);
arrList.Add(txtPhoneNo.Text);
if (textIn.Text != "" && txtPhoneNo.Text != "")
{
textOut.SetText(textIn.Text + " : " + txtPhoneNo.Text, TextView.BufferType.Normal);
container.AddView(addView);
Button btnCall = (Button)addView.FindViewById(Resource.Id.btnCall);
btnCall.Click += BtnCall_Click;
Button buttonRemove = (Button)addView.FindViewById(Resource.Id.remove);
buttonRemove.Click += ButtonRemove_Click;
}
else
{
Toast.MakeText(this, "Field can not be blank.", ToastLength.Short).Show();
}
}
private void BtnCall_Click(object sender, EventArgs e)
{
var callDialog = new AlertDialog.Builder(this);
string strNo = After(textOut.Text,":");
callDialog.SetMessage("Call " + strNo + "?");
callDialog.SetNeutralButton("Call", delegate
{
var callIntent = new Intent(Intent.ActionCall);
callIntent.SetData(Android.Net.Uri.Parse("tel:" + strNo));
StartActivity(callIntent);
});
callDialog.SetNegativeButton("Cancel", delegate { });
// Show the alert dialog to the user and wait for response.
callDialog.Show();
}
}
}
Main.axml
<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:paddingBottom="#dimen/activity_vertical_margin"
android:paddingLeft="#dimen/activity_horizontal_margin"
android:paddingRight="#dimen/activity_horizontal_margin"
android:paddingTop="#dimen/activity_vertical_margin"
android:orientation="vertical"
tools:context=".MainActivity">
<EditText
android:id="#+id/textin"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:hint="name" />
<EditText
android:id="#+id/txtPhoneNo"
android:layout_width="345.0dp"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:hint="Phone No." />
<Button
android:id="#+id/add"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:text="Add" />
<LinearLayout
android:id="#+id/container"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical" />
</LinearLayout>
row.xml
<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="wrap_content">
<Button
android:id="#+id/remove"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:text="Remove"/>
<Button
android:id="#+id/btnCall"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_toLeftOf="#id/remove"
android:text="Call"/>
<EditText
android:id="#+id/textout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_toLeftOf="#id/remove"/>
</RelativeLayout>
No you can't
you cannot store controls dynamically into your xml layout.
Either you add it manually into xml or you can create separate xml for control and then include it xml into your parent xml
<include
android:layout="id of your layout"
//height ... width
/>
In both ways, you have to create xml.
We are creating xml and inflate it in our java class. what you want to do is totally reverse of that.
Update
use shared preference
SharedPreference shared= context.getSharedPreferences("your preference name",
Context.MODE_PRIVATE);
String value = shared.getString("UserPhone","no data");
//set this value to your control
I think you need to refer SharedPreferences in android. This will serve your purpose.
In my project, im going to make a multiple choice type question. I can select the questions and answer from mysql, however, i cant do the "matching" of the answer between input answer and the data from mysql. I tried some solutions but they doesnt work as well. I need a big help on it. Below are my codes.
the java class that make multiple choice
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.normalmode);
new DataAsyncTask().execute();
}
public void onClick(View v){
inputtext = ((Button) v).getText().toString();
tv3 = (TextView)findViewById(R.id.textView3);
tv3.setText(inputtext);
if(inputtext == tv2.getText().toString()){
playerscore +=5;
} else {
playerscore +=1;
}
score.setText("Scores : " + playerscore);
new DataAsyncTask().execute();
}
class DataAsyncTask extends AsyncTask<String, String, String>{
#Override
protected String doInBackground(String... param) {
String result = DBConnector.executeQuery("SELECT * FROM questions ORDER BY RAND( ) LIMIT 1");
return result;
}
#Override
protected void onPostExecute(String result) {
question = (TextView)findViewById(R.id.textView_question);
fchoice = (Button)findViewById(R.id.Btn_choice1);
schoice = (Button)findViewById(R.id.Btn_choice2);
tchoice = (Button)findViewById(R.id.Btn_choice3);
tv2 = (TextView)findViewById(R.id.textView2);
score = (TextView)findViewById(R.id.textView_score);
try {
JSONArray jsonArray = new JSONArray(result);
JSONObject jsonData = jsonArray.getJSONObject(0);
question.setText(jsonData.getString("q_desc"));
fchoice.setText(jsonData.getString("fchoice"));
schoice.setText(jsonData.getString("schoice"));
tchoice.setText(jsonData.getString("tchoice"));
ans = jsonData.getString("q_ans");
tv2.setText(ans);
} catch(Exception e) {
Log.e("log_tag", e.toString());
}
}
}
}
three buttons are sharing same onClick in xml file by using
android:onClick="onClick"
the current problem i faced is that it always return "false" no matter i pressed which button. also, is there any way to store/pass "previous" async task data?
I have tried using internal storage but it doesnt work as well
EDIT:
my xml file
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/LinearLayout1"
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:layout_weight="0.95" >
<TextView
android:id="#+id/textView_score"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/player_score" />
</RelativeLayout>
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="0.95" >
<TextView
android:id="#+id/textView_question"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true"
android:text="#string/string_question"
android:textAppearance="?android:attr/textAppearanceMedium" />
<Button
android:id="#+id/Btn_choice3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_alignParentLeft="true"
android:layout_alignParentRight="true"
android:text="#string/third_choice"
android:onClick="onClick" />
<Button
android:id="#+id/Btn_choice2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_above="#+id/Btn_submit"
android:layout_alignParentLeft="true"
android:layout_alignParentRight="true"
android:text="#string/second_choice"
android:onClick="onClick" />
<Button
android:id="#+id/Btn_choice1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_above="#+id/Btn_choice2"
android:layout_alignParentLeft="true"
android:layout_alignParentRight="true"
android:text="#string/first_choice"
android:onClick="onClick" />
</RelativeLayout>
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content" >
<TextView
android:id="#+id/textView2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_alignParentTop="true"
android:text="TextView" />
<TextView
android:id="#+id/textView3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_toRightOf="#+id/textView1"
android:text="TextView" />
</RelativeLayout>
</LinearLayout
textview2 and textview3 are used to test my output and display them as text
try this if(inputtext.equals(tv2.getText().toString())) instead of if(inputtext == tv2.getText().toString())
becasue the == operator checks to see if the two strings are exactly the same object.
The .equals() method will check if the two strings have the same value.