I have three fragments, Player1Tun, Player2Turn and TicTacToeLayout. Player1Turn and Player2Turn are inner-switching every time a player makes a move and TicTacToeLayout contains the tic tac toe table which update everytime the fragments switches. What I'm trying to do is to send the data from either player fragments to the host activity (while the program is still running) and then from there, I'll update the table in the TicTacToeLayout. Any ideas or method I can do it?
Player1:
package As2.packageTK;
//import android.app.Activity;
import java.util.ArrayList;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentManager;
import android.support.v4.app.FragmentTransaction;
import android.app.Activity;
import android.os.Bundle;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;
import android.widget.Toast;
public class PlayerTurn2 extends Fragment{
TextView p2Name;
TextView p2Icon;
Button doneP2;
Button resetP2;
EditText row;
EditText column;
TicTacToeLayout myObject2 = new TicTacToeLayout();
ArrayList<String> player2;
Bundle extras = new Bundle();
int turn = 2;
public View onCreateView(LayoutInflater inflater,
ViewGroup container, Bundle savedInstanceState) {
View view = inflater.inflate(R.layout.playerturn2, container, false);
return view;
}
public void onActivityCreated(Bundle savedInstanceState) {
super.onActivityCreated(savedInstanceState);
extras = getArguments();
player2 = new ArrayList<String>(extras.getStringArrayList("player2"));
//Toast.makeText(getActivity(), player2.get(0), Toast.LENGTH_LONG).show();
//Toast.makeText(getActivity(), player2.get(1), Toast.LENGTH_LONG).show();
p2Name = (TextView) getActivity().findViewById(R.id.p2NameInfo);
p2Icon = (TextView) getActivity().findViewById(R.id.p2IconInfo);
row = (EditText) getActivity().findViewById(R.id.rowP2);
column = (EditText) getActivity().findViewById(R.id.columnP2);
doneP2 = (Button) getActivity().findViewById(R.id.doneP2);
//resetP2 = (Button) getActivity().findViewById(R.id.resetP2);
setPlayer(); //sets all the information of player 2, name, icon, image, etc
doneP2.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
callPlayer1Fragment(); //switches with first player
}
});
}
public void callPlayer1Fragment()
{
FragmentManager fm = getFragmentManager();
FragmentTransaction ft = fm.beginTransaction();
Fragment Player1Frag = new PlayerTurn1();
Player1Frag.setArguments(extras);
ft.replace(R.id.fragment_container, Player1Frag);
ft.commit();
}
public boolean checkField()
{
if(row == null || column == null)
{
Toast.makeText(getActivity(), "Please input the row or column!", Toast.LENGTH_LONG).show();
return false;
}
else
return true;
}
public void setPlayer()
{
String name = player2.get(0);
if(!name.equals(""))
p2Name.setText("Player Name: " + name);
else
p2Name.setText("");
String icon = player2.get(1);
if(!icon.equals(""))
p2Icon.setText("Player Icon: " + icon);
else
p2Icon.setText("");
}
}
player 2 fragment is exactly the same code so I won't bother adding it.
TicTacToeLayout fragment class:
public class TicTacToeLayout extends Fragment {
TextView image1, image2, image3, image4, image5, image6, image7, image8, image9;
TextView[][] images;
public View onCreateView(LayoutInflater inflater,
ViewGroup container, Bundle savedInstanceState) {
return inflater.inflate(R.layout.tictactoe_layout, container, false);
}
public void onActivityCreated(Bundle savedInstanceState) {
super.onActivityCreated(savedInstanceState);
image1 = (TextView) getActivity().findViewById(R.id.Image1);
image2 = (TextView) getActivity().findViewById(R.id.Image2);
image3 = (TextView) getActivity().findViewById(R.id.Image3);
image4 = (TextView) getActivity().findViewById(R.id.Image4);
image5 = (TextView) getActivity().findViewById(R.id.Image5);
image6 = (TextView) getActivity().findViewById(R.id.Image6);
image7 = (TextView) getActivity().findViewById(R.id.Image7);
image8 = (TextView) getActivity().findViewById(R.id.Image8);
image9 = (TextView) getActivity().findViewById(R.id.Image9);
images = new TextView[][]{ {image1, image2, image3},
{image4, image5, image6},
{image7, image8, image9} };
toast();
}
public void toast()
{
Toast.makeText(getActivity(), images[0][0].getText().toString(), Toast.LENGTH_LONG).show();
Toast.makeText(getActivity(), images[0][1].getText().toString(), Toast.LENGTH_LONG).show();
Toast.makeText(getActivity(), images[0][2].getText().toString(), Toast.LENGTH_LONG).show();
Toast.makeText(getActivity(), images[1][0].getText().toString(), Toast.LENGTH_LONG).show();
}
public void play(int row, int column, String icon)
{
images[row-1][column-1].setText(icon);
}
}
here's the XML layout for playerturn2
<?xml version="1.0" encoding="UTF-8"?>
<TableLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent" >
<TableRow
android:id="#+id/tablerow0"
android:layout_width="wrap_content"
android:layout_height="wrap_content" >
<TextView
android:id="#+id/player2Num"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginBottom="30dp"
android:layout_marginLeft="100dp"
android:gravity="center_horizontal"
android:text="Player 2"
android:textSize="20dp" />
</TableRow>
<TableRow
android:id="#+id/tablerow1"
android:layout_width="wrap_content"
android:layout_height="wrap_content" >
<TextView
android:id="#+id/p2NameInfo"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Player Name: "
android:textSize="20dp" />
</TableRow>
<TableRow
android:id="#+id/tablerow2"
android:layout_width="wrap_content"
android:layout_height="wrap_content" >
<TextView
android:id="#+id/p2IconInfo"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Player icon: "
android:textSize="20dp" />
</TableRow>
<TableRow
android:id="#+id/tablerow3"
android:layout_width="wrap_content"
android:layout_height="wrap_content" >
<TextView
android:id="#+id/p2PicInfo"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Player picture:"
android:textSize="20dp" />
</TableRow>
<ImageView
android:id="#+id/imageView1"
android:layout_width="100dp"
android:layout_height="100dp"
android:src="#android:drawable/editbox_background" />
<TableRow
android:id="#+id/rowNumber"
android:layout_width="wrap_content"
android:layout_height="wrap_content" >
<TextView
android:id="#+id/TextView01"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginBottom="30dp"
android:layout_marginLeft="50dp"
android:gravity="center_horizontal"
android:text="Row (1-3):"
android:textSize="20dp" />
<EditText
android:id="#+id/rowP2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:ems="10"
android:inputType="number"
android:width="50dp" />
</TableRow>
<TableRow
android:id="#+id/colNumber"
android:layout_width="wrap_content"
android:layout_height="wrap_content" >
<TextView
android:id="#+id/TextView02"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginBottom="30dp"
android:layout_marginLeft="50dp"
android:gravity="center_horizontal"
android:text="Col (1-3):"
android:textSize="20dp" />
<EditText
android:id="#+id/columnP2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:ems="10"
android:inputType="number"
android:width="50dp" />
</TableRow>
<TableRow
android:id="#+id/tableRow1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="50dp" >
<Button
android:id="#+id/doneP2"
android:layout_width="50dp"
android:layout_height="wrap_content"
android:text="Done"
/>
<Button
android:id="#+id/resetP2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Reset"
/>
</TableRow>
</TableLayout>
here's the layout for tictactoelayout.xml
<?xml version="1.0" encoding="UTF-8"?>
<TableLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/tictactoe"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_marginLeft="10dp" >
<TableRow
android:id="#+id/tableRow1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="30dp" >
<TextView
android:id="#+id/Image1"
android:layout_width="100dp"
android:layout_height="100dp"
android:text="1"
android:textSize="70dp" />
<TextView
android:id="#+id/Image2"
android:layout_width="100dp"
android:layout_height="100dp"
android:text="2"
android:textSize="70dp" />
<TextView
android:id="#+id/Image3"
android:layout_width="100dp"
android:layout_height="100dp"
android:text="3"
android:textSize="70dp" />
</TableRow>
<TableRow
android:id="#+id/tableRow2"
android:layout_width="wrap_content"
android:layout_height="wrap_content" >
<TextView
android:id="#+id/Image4"
android:layout_width="100dp"
android:layout_height="100dp"
android:text="4"
android:textSize="70dp" />
<TextView
android:id="#+id/Image5"
android:layout_width="100dp"
android:layout_height="100dp"
android:text="5"
android:textSize="70dp" />
<TextView
android:id="#+id/Image6"
android:layout_width="100dp"
android:layout_height="100dp"
android:text="6"
android:textSize="70dp" />
</TableRow>
<TableRow
android:id="#+id/tableRow3"
android:layout_width="wrap_content"
android:layout_height="wrap_content" >
<TextView
android:id="#+id/Image7"
android:layout_width="100dp"
android:layout_height="100dp"
android:text="7"
android:textSize="70dp" />
<TextView
android:id="#+id/Image8"
android:layout_width="100dp"
android:layout_height="100dp"
android:text="8"
android:textSize="70dp" />
<TextView
android:id="#+id/Image9"
android:layout_width="100dp"
android:layout_height="100dp"
android:text="9"
android:textSize="70dp" />
</TableRow>
<RelativeLayout
android:layout_width="wrap_content"
android:layout_height="match_parent" >
<TextView
android:id="#+id/win"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_centerVertical="true"
android:text="Winner"
android:textSize="20dp" />
<EditText
android:id="#+id/winner"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_centerVertical="true"
android:layout_marginRight="15dp"
android:ems="10" />
</RelativeLayout>
</TableLayout>
and finally the host activity's xml layout: tictactoegame.xml
<?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="horizontal" >
<FrameLayout
android:id="#+id/fragment_container"
android:layout_width="0px"
android:layout_height="match_parent"
android:layout_weight="1" />
<fragment
android:id="#+id/frag2"
android:name="As2.packageTK.TicTacToeLayout"
android:layout_width="0px"
android:layout_height="match_parent"
android:layout_weight="1" />
</LinearLayout>
My friend did the same but with a implementing an interface he created in the fragments and having the main activity implement the interface. With that, he used a method to pass datas. Maybe it's not clear but if you know what I'm trying to say then you could clear it out for all of us :)
your friend is right, communicating with other fragments is nicely explained in the docs:
http://developer.android.com/training/basics/fragments/communicating.html
Related
I am try to save my roll no and name in main activity but when my screen is rotated the activity data has been lose ,
finally i fixed it , below i adding source code
consider any layout , here i am using this layout structure
In activity_xml :
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout 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:orientation="vertical"
android:padding="20dp"
tools:context=".MainActivity">
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="horizontal">
<TextView
android:id="#+id/rollnoID"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="15dp"
android:layout_marginTop="10dp"
android:text="Rollno : "
android:textSize="25dp" />
<EditText
android:hint="Roll Number"
android:id="#+id/rollnoID_edit"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="15dp"
android:layout_marginTop="10dp"
android:ems="8"
android:inputType="number"
android:text=""
android:textSize="25dp" />
</LinearLayout>
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="horizontal">
<TextView
android:id="#+id/nameID"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="15dp"
android:layout_marginTop="10dp"
android:text="Name : "
android:textSize="25dp" />
<EditText
android:hint="Student Name"
android:id="#+id/nameID_edit"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="15dp"
android:layout_marginTop="10dp"
android:ems="8"
android:inputType="textCapWords"
android:text=""
android:textSize="25dp" />
</LinearLayout>
<Button
android:onClick="saveData"
android:id="#+id/saveButton"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="save this Data"
android:textSize="20sp" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginTop="20dp"
android:padding="20dp"
android:orientation="vertical">
<TextView
android:gravity="center"
android:hint="~RollNo~"
android:textColor="#color/colorPrimary"
android:id="#+id/display_rollno"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textSize="30sp" />
<TextView
android:layout_marginTop="20dp"
android:id="#+id/display_name"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center"
android:hint="~Name~"
android:textColor="#color/colorPrimary"
android:textSize="30sp" />
</LinearLayout>
</LinearLayout>
In MainActivity :
import androidx.appcompat.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;
import android.widget.Toast;
public class MainActivity extends AppCompatActivity {
private static final String KEY_ROLL = "rollno_key";
private static final String KEY_NAME = "name_key";
int rollno;
String name;
EditText roll_et , name_et;
TextView roll_tv , name_tv;
Button saveButton;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
roll_et = (EditText) findViewById(R.id.rollnoID_edit);
name_et = (EditText) findViewById(R.id.nameID_edit);
roll_tv = (TextView) findViewById(R.id.display_rollno);
name_tv = (TextView) findViewById(R.id.display_name);
if (savedInstanceState != null){
String save_RollNO = savedInstanceState.getString(KEY_ROLL);
roll_tv.setText(save_RollNO);
String save_Name = savedInstanceState.getString(KEY_NAME);
name_tv.setText(save_Name);
} else {
Toast.makeText(getApplicationContext(),"Entry your data",Toast.LENGTH_SHORT).show();
}
}
#Override
public void onSaveInstanceState(Bundle saveData) {
saveData.putString(KEY_ROLL , roll_et.getText().toString());
saveData.putString(KEY_NAME , name_et.getText().toString());
super.onSaveInstanceState(saveData);
}
public void saveData(View v){
roll_tv.setText(roll_et.getText().toString().trim());
name_tv.setText(name_et.getText().toString().trim());
}
}
I would like to display all the registerEventName inside the spinner in order to let the user to select from it. But how to get the data from firebase and display inside the spinner? Hope someone can help me on this.
XML File
For example i want to change EditText of eventTitle to spinner.
<?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"
android:id="#+id/createEventLayout"
>
<ScrollView
android:layout_width="match_parent"
android:layout_height="match_parent">
<LinearLayout
android:layout_width="match_parent"
android:orientation="vertical"
android:layout_height="wrap_content">
<LinearLayout
android:layout_width="match_parent"
android:weightSum="10"
android:background="#89bcd4"
android:padding="10dp"
android:layout_height="wrap_content">
<TextView
android:layout_width="0dp"
android:layout_weight="4"
android:text="Title of event"
android:layout_height="wrap_content" />
<EditText
android:id="#+id/eventTitle"
android:layout_width="0dp"
android:inputType="text"
android:maxLines="1"
android:lines="1"
android:layout_weight="6"
android:imeOptions="actionNext"
android:layout_height="wrap_content" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:weightSum="10"
android:background="#dce2e6"
android:padding="10dp"
android:layout_height="wrap_content">
<TextView
android:layout_width="0dp"
android:layout_weight="4"
android:text="#string/createEventDesc"
android:layout_height="wrap_content" />
<EditText
android:id="#+id/eventDes"
android:layout_width="0dp"
android:layout_weight="6"
android:lines="1"
android:inputType="text"
android:maxLines="1"
android:imeOptions="actionNext"
android:layout_height="wrap_content" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:weightSum="10"
android:background="#89bcd4"
android:padding="10dp"
android:layout_height="wrap_content">
<TextView
android:layout_width="0dp"
android:layout_weight="4"
android:text="#string/createEventLocation"
android:layout_height="wrap_content" />
<EditText
android:maxLines="1"
android:lines="1"
android:id="#+id/eventLocation"
android:layout_width="0dp"
android:layout_weight="6"
android:inputType="text"
android:imeOptions="actionNext"
android:layout_height="wrap_content" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:weightSum="10"
android:background="#dce2e6"
android:padding="10dp"
android:layout_height="wrap_content">
<TextView
android:layout_width="0dp"
android:layout_weight="4"
android:text="Employee email"
android:layout_height="wrap_content" />
<EditText
android:id="#+id/eventAttendee"
android:layout_width="0dp"
android:layout_weight="6"
android:hint="Place more attendee by comma seprated"
android:maxLines="1"
android:lines="1"
android:inputType="textEmailAddress"
android:imeOptions="actionNext"
android:layout_height="wrap_content" />
</LinearLayout>
<LinearLayout
android:orientation="horizontal"
android:layout_width="match_parent"
android:background="#89bcd4"
android:padding="10dp"
android:layout_height="wrap_content">
<TextView
android:id="#+id/startAt"
android:layout_width="0dp"
android:layout_weight="3"
android:text="#string/createEventStart"
android:layout_height="wrap_content" />
<LinearLayout
android:orientation="vertical"
android:layout_width="0dp"
android:layout_weight="7"
android:layout_height="wrap_content">
<DatePicker
android:id="#+id/startDate"
android:layout_width="wrap_content"
android:calendarViewShown="false"
android:datePickerMode="spinner"
android:layout_weight="4"
android:layout_height="wrap_content" />
<TimePicker
android:id="#+id/startTime"
android:layout_width="wrap_content"
android:layout_weight="4"
android:timePickerMode="spinner"
android:layout_height="wrap_content" />
</LinearLayout>
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:orientation="horizontal"
android:background="#dce2e6"
android:padding="10dp"
android:layout_height="wrap_content">
<TextView
android:id="#+id/endAt"
android:layout_width="0dp"
android:layout_weight="3"
android:text="#string/createEventEnd"
android:layout_height="wrap_content" />
<LinearLayout
android:layout_width="0dp"
android:orientation="vertical"
android:layout_weight="7"
android:layout_height="wrap_content">
<DatePicker
android:id="#+id/endDate"
android:layout_width="wrap_content"
android:calendarViewShown="false"
android:datePickerMode="spinner"
android:layout_height="wrap_content" />
<TimePicker
android:id="#+id/endTime"
android:timePickerMode="spinner"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
</LinearLayout>
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:weightSum="10"
android:background="#89bcd4"
android:padding="10dp"
android:layout_height="wrap_content">
<Button
android:maxLines="1"
android:id="#+id/createEvent"
android:layout_width="0dp"
android:layout_weight="5"
android:text="Create Event"
android:layout_height="wrap_content" />
<Button
android:id="#+id/cancelEvent"
android:layout_width="0dp"
android:layout_weight="5"
android:text="Cancel"
android:layout_height="wrap_content" />
</LinearLayout>
</LinearLayout>
</ScrollView>
</LinearLayout>
Event List Adapter Java File
package com.example.edward.neweventmanagementsystem.adapter;
import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.AutoCompleteTextView;
import android.widget.BaseAdapter;
import android.widget.Spinner;
import android.widget.TextView;
import com.example.edward.neweventmanagementsystem.R;
import com.example.edward.neweventmanagementsystem.Model.ScheduledEvents;
import com.google.firebase.database.DataSnapshot;
import com.google.firebase.database.DatabaseReference;
import com.google.firebase.database.FirebaseDatabase;
import com.google.firebase.database.ValueEventListener;
import java.util.ArrayList;
import java.util.List;
/**
* Created by Khushvinders on 21-Oct-16.
*/
public class EventListAdapter extends BaseAdapter {
private Context context;
private List<ScheduledEvents> scheduledEvents;
private LayoutInflater inflater;
FirebaseDatabase database;
public EventListAdapter(Context context, List<ScheduledEvents> scheduledEvents){
this.context = context;
this.scheduledEvents = scheduledEvents;
inflater = LayoutInflater.from(this.context);
}
#Override
public int getCount() {
return scheduledEvents.size();
}
#Override
public Object getItem(int i) {
return scheduledEvents.get(i);
}
#Override
public long getItemId(int i) {
return 0;
}
#Override
public View getView(int position, View convertView, ViewGroup parent) {
EventHolder eventHolder;
if (convertView == null) {
convertView = inflater.inflate(R.layout.event_view_layout, parent, false);
eventHolder = new EventHolder(convertView);
convertView.setTag(eventHolder);
} else {
eventHolder = (EventHolder) convertView.getTag();
}
ScheduledEvents scheduledEvents = (ScheduledEvents) getItem(position);
eventHolder.eventTitle.setText(scheduledEvents.getEventSummery());
eventHolder.eventDes.setText(scheduledEvents.getDescription());
eventHolder.eventAttendee.setText(scheduledEvents.getAttendees());
eventHolder.eventStart.setText(scheduledEvents.getStartDate());
eventHolder.eventEnd.setText(scheduledEvents.getEndDate());
eventHolder.eventLocation.setText(scheduledEvents.getLocation());
return convertView;
}
private class EventHolder {
TextView eventDes, eventAttendee, eventStart, eventEnd, eventLocation, eventTitle;
public EventHolder(View item) {
eventTitle = (TextView) item.findViewById(R.id.eventTitle);
eventDes = (TextView) item.findViewById(R.id.eventDes);
eventAttendee = (TextView) item.findViewById(R.id.eventAttendee);
eventStart = (TextView) item.findViewById(R.id.eventStart);
eventEnd = (TextView) item.findViewById(R.id.eventEnd);
eventLocation = (TextView) item.findViewById(R.id.eventLocation);
}
}
}
Sample of firebase database
I am trying to do for each customer and destination should have a photo by saving the path of this photo in the database in order to retrieve it again.
Here is my code:
package com.example.pr;
import ItemsAndDatabase.Destination_Item;
import ItemsAndDatabase.Flight_Item;
import android.R.string;
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Toast;
public class AddDestination extends Activity {
private int customer_id;
private string name;
private int passportNo;
private int ID;
private string addr;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.add_new_destination);
final EditText txtName = (EditText) findViewById(R.id.editText1);
final EditText CusID = (EditText) findViewById(R.id.editText2);
final EditText Pass = (EditText) findViewById(R.id.editText3);
final EditText photo = (EditText) findViewById(R.id.editText4);
final EditText Addr = (EditText) findViewById(R.id.editText5);
Button btnAddNewcustomer = (Button) findViewById(R.id.button1);
Button back = (Button) findViewById(R.id.button2);
back.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
finish();
Intent myIntent = new Intent(AddDestination.this,
destination.class);
AddDestination.this.startActivity(myIntent);
}
});
btnAddNewcustomer.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
if (!txtName.getText().toString().isEmpty()
&& !CusID.getText().toString().isEmpty()
&& !Pass.getText().toString().isEmpty()) {
Destination_Item item = new Destination_Item();
item.setName(txtName.getText().toString());
item.setCountry(CusID.getText().toString() );
item.setLongg(Pass.getText().toString() );
item.setLatt(photo.getText().toString() );
item.setPhoto(Addr.getText().toString() );
MainActivity.db.addDestination(item);
Toast.makeText(AddDestination.this,
"Destination Added Successfully", Toast.LENGTH_LONG)
.show();
finish();
} else {
Toast.makeText(AddDestination.this, "Please Fill All fields",
Toast.LENGTH_LONG).show();
}
}
});
}
}
And this is my XML file:
<?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:layout_marginLeft="10dip"
android:layout_marginTop="10dip"
android:orientation="vertical" >
<TableLayout
android:layout_width="match_parent"
android:layout_height="wrap_content" >
<TableRow
android:id="#+id/tableRow2"
android:layout_width="wrap_content"
android:layout_height="wrap_content" >
<TextView
android:id="#+id/textView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Name"
android:textAppearance="?android:attr/textAppearanceSmall" />
<EditText
android:id="#+id/editText1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:ems="10" >
<requestFocus />
</EditText>
</TableRow>
<TableRow
android:id="#+id/tableRow3"
android:layout_width="wrap_content"
android:layout_height="wrap_content" >
<TextView
android:id="#+id/textView2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Country"
android:textAppearance="?android:attr/textAppearanceSmall" />
<EditText
android:id="#+id/editText2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:ems="10" />
</TableRow>
<TableRow
android:id="#+id/tableRow4"
android:layout_width="wrap_content"
android:layout_height="wrap_content" >
<TextView
android:id="#+id/textView3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Long"
android:textAppearance="?android:attr/textAppearanceSmall" />
<EditText
android:id="#+id/editText3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:ems="10" />
</TableRow>
<TableRow
android:id="#+id/tableRow1"
android:layout_width="wrap_content"
android:layout_height="wrap_content" >
<TextView
android:id="#+id/textView4"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Lat" />
<EditText
android:id="#+id/editText4"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:ems="10" />
</TableRow>
<TableRow
android:id="#+id/tableRow5"
android:layout_width="wrap_content"
android:layout_height="wrap_content" >
<TextView
android:id="#+id/textView5"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Photo"
android:textAppearance="?android:attr/textAppearanceSmall" />
<EditText
android:id="#+id/editText5"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:ems="10" />
</TableRow>
</TableLayout>
<Button
android:id="#+id/button1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:text="Add Destination" />
<Button
android:id="#+id/button2"
android:layout_width="126dp"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:text="back" />
</LinearLayout>
any idea how to do this ?
thanks in advance.
Are you going to let the user take a photo during the sign up?
you should change the photo into an ImageView instead of using EditText.
If you are going let the user take a picture or use an image from gallery, use the developer in android or use Androidhive.com
I have created my first android application I have 4 pages, I have set one page to be the menu and it has 3 buttons on it to switch between the pages. However I seem to be getting an error in my code, if someone could take a look and see where I am going wrong with this.
So this is my menu page (activity_main)
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="#+id/container"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context="com.example.ifmdb.MainActivity"
tools:ignore="MergeRootFrame,HardcodedText" >
<TextView
android:id="#+id/txtMain"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true"
android:layout_gravity="center"
android:text="#string/please_click_on_the_options_available"
android:textAppearance="?android:attr/textAppearanceMedium" />
<Button
android:id="#+id/btnDOCare"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignRight="#+id/txtDOCare"
android:layout_below="#+id/txtDOCare"
android:layout_marginTop="30dp"
android:layout_gravity="center_vertical"
android:onClick="openDOCare"
android:text="#string/duty_of_care" />
<TextView
android:id="#+id/txtDOCare"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_below="#+id/btnDock"
android:layout_marginLeft="202dp"
android:layout_marginTop="44dp"
android:layout_gravity="center"
android:text="#string/click_for_duty_of_care"
android:textAppearance="?android:attr/textAppearanceMedium" />
<TextView
android:id="#+id/txtVeCheck"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignLeft="#+id/txtDOCare"
android:layout_below="#+id/txtMain"
android:layout_marginTop="36dp"
android:text="#string/click_for_vehicle_checklist"
android:textAppearance="?android:attr/textAppearanceMedium" />
<Button
android:id="#+id/btnCheck"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignLeft="#+id/btnDOCare"
android:layout_below="#+id/txtVeCheck"
android:layout_marginTop="37dp"
android:onClick="openChecklist"
android:text="#string/checklist" />
<TextView
android:id="#+id/txtDock"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignRight="#+id/txtDOCare"
android:layout_below="#+id/btnCheck"
android:layout_marginTop="36dp"
android:text="#string/click_for_docket"
android:textAppearance="?android:attr/textAppearanceMedium" />
<Button
android:id="#+id/btnDock"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignRight="#+id/btnCheck"
android:layout_below="#+id/txtDock"
android:layout_marginTop="38dp"
android:onClick="openDocket"
android:text="#string/docket" />
</RelativeLayout>
and this is my Java class for it (Main Activity)
package com.example.ifmdb;
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.view.View;
import android.widget.Button;
public class MainActivity extends Activity {
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
Button btnHome = (Button)findViewById(R.id.btnHome);
btnHome.setOnClickListener(new View.OnClickListener() {
public void onClick(View view) {
Intent myIntent = new Intent(view.getContext(),
startActivityForResult(myIntent, 0);
}
});
}
}
This is my second page (checklist)
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="#+id/LinearLayout1"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
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.example.ifmdb.MainActivity$PlaceholderFragment" >
<TextView
android:id="#+id/txtTitle"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/vehicle_safety_checklist"
android:textAppearance="?android:attr/textAppearanceLarge" />
<TextView
android:id="#+id/txtInfo"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/please_check_each_box"
android:textAppearance="?android:attr/textAppearanceMedium" />
<RelativeLayout
android:layout_width="wrap_content"
android:layout_height="0dp"
android:layout_weight="0.58" >
<TextView
android:id="#+id/txtInt"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true"
android:layout_marginTop="20dp"
android:text="#string/interior"
android:textAppearance="?android:attr/textAppearanceMedium" />
<TextView
android:id="#+id/txtEx"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignBaseline="#+id/txtInt"
android:layout_alignBottom="#+id/txtInt"
android:layout_alignParentRight="true"
android:layout_marginRight="113dp"
android:text="#string/exterior"
android:textAppearance="?android:attr/textAppearanceMedium" />
<CheckBox
android:id="#+id/cboxFLev"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_below="#+id/txtInt"
android:text="#string/fuel_level" />
<CheckBox
android:id="#+id/cboxTires"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignBaseline="#+id/cboxFLev"
android:layout_alignBottom="#+id/cboxFLev"
android:layout_alignLeft="#+id/txtEx"
android:text="#string/tires_wheels" />
<CheckBox
android:id="#+id/cboxWWash"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_below="#+id/cboxFLev"
android:text="#string/windscreen_washer" />
<CheckBox
android:id="#+id/cboxExhaust"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignBaseline="#+id/cboxWWash"
android:layout_alignBottom="#+id/cboxWWash"
android:layout_alignLeft="#+id/cboxTires"
android:text="#string/exhaust" />
<CheckBox
android:id="#+id/cboxSWheel"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_below="#+id/cboxWWash"
android:text="#string/steering_wheel" />
<CheckBox
android:id="#+id/cboxLights"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignBaseline="#+id/cboxSWheel"
android:layout_alignBottom="#+id/cboxSWheel"
android:layout_alignLeft="#+id/cboxExhaust"
android:text="#string/lights_reflectors" />
<CheckBox
android:id="#+id/cboxBrakes"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_below="#+id/cboxSWheel"
android:text="#string/brakes" />
<CheckBox
android:id="#+id/cboxELeaks"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignBaseline="#+id/cboxBrakes"
android:layout_alignBottom="#+id/cboxBrakes"
android:layout_alignLeft="#string/_id_cboxlights"
android:text="#string/exterior_leaks" />
<CheckBox
android:id="#+id/cboxClutch"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_below="#+id/cboxBrakes"
android:text="#string/clutch" />
<CheckBox
android:id="#+id/cbocBody"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignBaseline="#+id/cboxClutch"
android:layout_alignBottom="#+id/cboxClutch"
android:layout_alignLeft="#string/_id_cboxeleaks"
android:text="#string/body" />
<CheckBox
android:id="#+id/cboxHorn"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_below="#+id/cboxClutch"
android:text="#string/horn" />
<TextView
android:id="#+id/txtEng"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignLeft="#+id/cbocBody"
android:layout_below="#+id/cboxHorn"
android:text="#string/engine"
android:textAppearance="?android:attr/textAppearanceMedium" />
<CheckBox
android:id="#+id/cboxHeater"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignTop="#+id/txtEng"
android:text="#string/heater" />
<CheckBox
android:id="#+id/cboxOil"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignRight="#+id/cboxExhaust"
android:layout_below="#+id/cboxHeater"
android:text="#string/oil_level" />
<CheckBox
android:id="#+id/cboxSBelt"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignBaseline="#+id/cboxOil"
android:layout_alignBottom="#+id/cboxOil"
android:layout_alignParentLeft="true"
android:text="#string/seat_belts" />
<CheckBox
android:id="#+id/cboxWLight"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignBaseline="#+id/cboxCool"
android:layout_alignBottom="#+id/cboxCool"
android:layout_alignParentLeft="true"
android:text="#string/warning_lights" />
<CheckBox
android:id="#+id/cboxBelt"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignLeft="#+id/cboxCool"
android:layout_below="#+id/cboxCool"
android:text="#string/belts" />
<CheckBox
android:id="#+id/cboxMirrors"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_below="#+id/cboxWLight"
android:text="#string/mirrors" />
<CheckBox
android:id="#+id/cboxLeaks"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignLeft="#+id/cboxBelt"
android:layout_below="#+id/cboxBelt"
android:text="#string/engine_leaks" />
<CheckBox
android:id="#+id/cboxCool"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignLeft="#+id/cboxOil"
android:layout_below="#+id/cboxOil"
android:text="#string/coolant_level" />
<TextView
android:id="#+id/txtOther"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignBottom="#+id/cboxLeaks"
android:layout_alignParentLeft="true"
android:text="#string/other"
android:textAppearance="?android:attr/textAppearanceMedium" />
<CheckBox
android:id="#+id/cboxScrew"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignLeft="#+id/txtEng"
android:layout_below="#+id/cboxLeaks"
android:text="#string/loose_bolts_screws" />
<CheckBox
android:id="#+id/cboxWTri"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignBaseline="#+id/cboxScrew"
android:layout_alignBottom="#+id/cboxScrew"
android:layout_alignParentLeft="true"
android:text="#string/warning_triangle" />
<CheckBox
android:id="#+id/cboxFire"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_below="#+id/cboxWTri"
android:text="#string/fire_extinguisher_first_aid_kit" />
<TextView
android:id="#+id/txtAddCom"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_centerVertical="true"
android:text="#string/additional_comments"
android:textAppearance="?android:attr/textAppearanceMedium" />
<TextView
android:id="#+id/txtAddComBox"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignRight="#+id/cboxLights"
android:layout_below="#+id/txtAddCom"
android:layout_marginTop="29dp" />
<TextView
android:id="#+id/txtFault"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_alignParentLeft="true"
android:layout_marginBottom="27dp"
android:text="#string/in_the_event_of_serious_faults_do_not_drive_the_vehicle"
android:textAppearance="?android:attr/textAppearanceMedium" />
<TextView
android:id="#+id/txtDefects"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_below="#+id/txtAddComBox"
android:layout_marginTop="110dp"
android:text="#string/defects"
android:textAppearance="?android:attr/textAppearanceMedium" />
<TextView
android:id="#+id/txtDefectsBox"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignRight="#+id/cboxScrew"
android:layout_below="#+id/txtDefects"
android:layout_marginTop="25dp" />
<Button
android:id="#+id/btnHome"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_toRightOf="#+id/cboxOil"
android:text="#string/home" />
</RelativeLayout>
</LinearLayout>
and this is that java class for that page (Checklist)
package com.example.ifmdb;
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
public class Checklist extends Activity {
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.checklist);
Button btnCheck = (Button) findViewById(R.id.btnCheck);
btnCheck.setOnClickListener(new View.OnClickListener() {
public void onClick(View view) {
Intent intent = new Intent();
setResult(RESULT_OK, intent);
finish();
}
});
}
}
I have an error with a line of code
Intent myIntent = new Intent(view.getContext(),
startActivityForResult(myIntent, 0);
This is the error---
The constructor Intent(Context, void) is undefined
Syntax error, insert ")" to complete Variable Initializer
Try this code
public class MainActivity extends Activity {
private Activity mActivity = null;
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
mActivity = this;
Button btnHome = (Button)findViewById(R.id.btnHome);
btnHome.setOnClickListener(new View.OnClickListener() {
public void onClick(View view) {
Intent myIntent = new Intent(mActivity.getApplicationContext(),Checklist.class);
mActivity.startActivityForResult(myIntent, 0);
}
});
}
}
In the code its missing the syntax.
here is a tutorial
You can try this way. Hope it helps.
btnHome.setOnClickListener(new View.OnClickListener() {
public void onClick(View view) {
Intent myIntent = new Intent(getActivity(),Checklist.class);
startActivity(myIntent);
}
});
I got it fixed, you were right Atul O Holic i was missing a part of the code.
heres the working solution
package com.example.ifmdb;
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.view.View;
import android.widget.Button;
public class MainActivity extends Activity {
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
Button btnHome = (Button)findViewById(R.id.btnHome);
btnHome.setOnClickListener(new View.OnClickListener() {
public void onClick(View view) {
Intent myIntent = new Intent(view.getContext(),Checklist.class);
startActivityForResult(myIntent, 0);
}
});
}
}
I'd like to capture the currently connected SSID - and display it in a TextView - how can this be done?
From what I can gather I'll need to use the following:
public void run() {
WifiManager wifi = (WifiManager) getSystemService(Context.WIFI_SERVICE);
WifiInfo info = wifi.getConnectionInfo();
String nameEt = info.getSSID();
}
But when I attempt to implement it - I cannot seem to display it on the screen.
JAVA:
import android.app.Activity;
import android.app.AlertDialog;
import android.content.Context;
import android.net.wifi.WifiInfo;
import android.net.wifi.WifiManager;
import android.os.AsyncTask;
import android.os.Bundle;
import android.view.ViewGroup;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.EditText;
import android.widget.FrameLayout;
import android.widget.TextView;
import android.widget.TimePicker;
import java.text.DecimalFormat;
public class AddEditDevice extends Activity {
private long rowID;
private EditText nameEt;
private EditText capEt;
private EditText codeEt;
private TimePicker timeEt;
private TextView ssid;
// DecimalFormat df = new DecimalFormat ("00");
// public String minutes = df.format(min);
// #Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.add_country);
nameEt = (EditText) findViewById(R.id.nameEdit);
capEt = (EditText) findViewById(R.id.capEdit);
codeEt = (EditText) findViewById(R.id.codeEdit);
timeEt = (TimePicker) findViewById(R.id.timeEdit);
Bundle extras = getIntent().getExtras();
if (extras != null) {
rowID = extras.getLong("row_id");
nameEt.setText(extras.getString("name"));
capEt.setText(extras.getString("cap"));
codeEt.setText(extras.getString("code"));
String time = extras.getString("time");
String[] parts = time.split(":");
timeEt.setCurrentHour(Integer.valueOf(parts[0]));
timeEt.setCurrentMinute(Integer.valueOf(parts[1]));
timeEt.setIs24HourView(false);
}
Button saveButton = (Button) findViewById(R.id.saveBtn);
saveButton.setOnClickListener(new OnClickListener() {
public void onClick(View v) {
if (nameEt.getText().length() != 0) {
AsyncTask<Object, Object, Object> saveContactTask =
new AsyncTask<Object, Object, Object>() {
#Override
protected Object doInBackground(Object... params) {
saveContact();
return null;
}
#Override
protected void onPostExecute(Object result) {
finish();
}
};
saveContactTask.execute((Object[]) null);
} else {
AlertDialog.Builder alert = new AlertDialog.Builder(
AddEditDevice.this);
alert.setTitle(R.string.errorTitle);
alert.setMessage(R.string.errorMessage);
alert.setPositiveButton(R.string.errorButton, null);
alert.show();
}
}
});
}
public void run() {
WifiManager wifi = (WifiManager) getSystemService(Context.WIFI_SERVICE);
WifiInfo info = wifi.getConnectionInfo();
String ssid = info.getSSID();
TextView ssidTextView = (TextView) findViewById(R.id.wifiSSID);
ssidTextView.setText(ssid);
}
private void saveContact() {
DatabaseConnector dbConnector = new DatabaseConnector(this);
if (getIntent().getExtras() == null) {
dbConnector.insertContact(nameEt.getText().toString(), capEt
.getText().toString(), timeEt.getCurrentHour().toString() + ":"
+ timeEt.getCurrentMinute().toString(), codeEt.getText()
.toString());
} else {
dbConnector.updateContact(rowID, nameEt.getText().toString(), capEt
.getText().toString(), timeEt.getCurrentHour().toString() + ":"
+ timeEt.getCurrentMinute().toString(), codeEt.getText()
.toString());
}
}
}
XML:
<?xml version="1.0" encoding="utf-8"?>
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_weight="1" >
<LinearLayout
android:id="#+id/linearLayout"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:padding="5dp" >
<EditText
android:id="#+id/nameEdit"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:ems="10"
android:hint="#string/name_hint"
android:imeOptions="actionNext"
android:inputType="textPersonName|textCapWords" />
<TextView
android:id="#+id/wifiSSID"
style="#style/StyleText"
android:layout_width="fill_parent"
android:layout_height="wrap_content" />
<EditText
android:id="#+id/capEdit"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:ems="10"
android:hint="#string/cap_hint"
android:imeOptions="actionNext"
android:inputType="textPersonName|textCapWords" >
<requestFocus />
</EditText>
<TextView
android:id="#+id/textView3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Data Limit"
android:textAppearance="?android:textAppearanceMedium"
android:textColor="#ffffff" />
<SeekBar
android:id="#+id/seekBar1"
android:layout_width="fill_parent"
android:layout_height="wrap_content" />
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="horizontal" >
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1.0"
android:gravity="left"
android:text="Unlimited Data"
android:textColor="#ffffff" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1.0"
android:gravity="right"
android:text="10MB"
android:textColor="#ffffff" />
</LinearLayout>
<TextView
android:id="#+id/textView3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Bandwidth Limit"
android:textAppearance="?android:textAppearanceMedium"
android:textColor="#ffffff" />
<SeekBar
android:id="#+id/seekBar1"
android:layout_width="fill_parent"
android:layout_height="wrap_content" />
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="horizontal" >
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1.0"
android:gravity="left"
android:text="Unlimited Bandwidth"
android:textColor="#ffffff" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1.0"
android:gravity="right"
android:text="10kbs"
android:textColor="#ffffff" />
</LinearLayout>
<EditText
android:id="#+id/codeEdit"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_weight="1.0"
android:ems="10"
android:gravity="center"
android:hint="#string/code_hint"
android:imeOptions="actionNext"
android:inputType="textUri"
android:lines="1" />
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="horizontal" >
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1.0"
android:gravity="center"
android:text="Parental Controls"
android:textColor="#ffffff" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1.0"
android:gravity="center"
android:text="Block Streaming"
android:textColor="#ffffff" />
</LinearLayout>
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="horizontal" >
<ToggleButton
android:id="#+id/ToggleButton03"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1.0"
android:gravity="center"
android:text="ToggleButton" />
<ToggleButton
android:id="#+id/ToggleButton03"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1.0"
android:gravity="center"
android:text="ToggleButton" />
</LinearLayout>
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="horizontal" >
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1.0"
android:gravity="center"
android:text="Block File Type/Size"
android:textColor="#ffffff" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1.0"
android:gravity="center"
android:text="Banned Music/Video"
android:textColor="#ffffff" />
</LinearLayout>
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="horizontal" >
<ToggleButton
android:id="#+id/ToggleButton02"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1.0"
android:gravity="center"
android:text="ToggleButton" />
<ToggleButton
android:id="#+id/ToggleButton02"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1.0"
android:gravity="center"
android:text="ToggleButton" />
</LinearLayout>
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:gravity="center"
android:orientation="horizontal" >
</LinearLayout>
<TextView
android:id="#+id/TextView02"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:textAppearanceSmall" />
<TextView
android:id="#+id/TextView02"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_marginBottom="8dp"
android:layout_weight="1.0"
android:text="WiFi Time Limit"
android:textAppearance="?android:textAppearanceMedium"
android:textColor="#ffffff" />
<TimePicker
android:id="#+id/timeEdit"
android:layout_width="286dp"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:layout_weight="1.0" />
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="left"
android:orientation="horizontal" >
</LinearLayout>
<Button
android:id="#+id/saveBtn"
android:layout_width="199dp"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:layout_marginTop="15dp"
android:text="#string/save_btn" />
</LinearLayout>
</ScrollView>
You aren't calling run() from anywhere, and that method is not trying to update a textview. Try doing this in your run method.
TextView ssidTextView = (TextView) findViewById(R.id.<your_textview_id>);
ssidTextView.setText(nameEt);
And thenmake sure you call run() whenever you want to update the ssid in the TextView.