EditText prints a letter twice - android

I know this is kinda silly and weird question, but its really bugging me. As my post subject says, when I enter a letter in the edit text its printing twice. I tried to find the issue, but couldn't. Here is my code,
changecode.xml
<EditText
android:id="#+id/oldcode"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="#id/changecodetxt"
android:layout_marginLeft="15dp"
android:layout_marginRight="15dp"
android:layout_marginTop="20dp"
android:hint="Enter Old Pass Code"
android:inputType="number"
android:password="true" />
<EditText
android:id="#+id/newcode"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="#id/oldcode"
android:layout_marginLeft="15dp"
android:layout_marginRight="15dp"
android:layout_marginTop="20dp"
android:hint="Enter New Pass code"
android:inputType="number"
android:password="true" />
<EditText
android:id="#+id/renewcode"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="#id/newcode"
android:layout_marginLeft="15dp"
android:layout_marginRight="15dp"
android:layout_marginTop="25dp"
android:hint="Re-Enter New Pass code"
android:inputType="number"
android:password="true" />
<Button
android:id="#+id/savenewcode"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_marginBottom="5dp"
android:layout_marginLeft="5dp"
android:layout_marginRight="5dp"
android:background="#drawable/button_style"
android:text="Update Code" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_above="#id/savenewcode"
android:layout_below="#id/renewcode"
android:gravity="center" >
<ToggleButton
android:id="#+id/cc_togglebutton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="10dp"
android:layout_marginBottom="10dp"
android:textOff="123"
android:textOn="ABC!##" />
</LinearLayout>
In MainActivity.java
oldcode = (EditText) findViewById(R.id.oldcode);
newcode = (EditText) findViewById(R.id.newcode);
renewcode = (EditText) findViewById(R.id.renewcode);
savenewcode = (Button) findViewById(R.id.savenewcode);
cc_toggle = (ToggleButton) findViewById(R.id.cc_togglebutton);
cc_toggle.setOnClickListener(new OnClickListener() {
#Override
public void onClick(View v) {
boolean on = cc_toggle.isChecked();
if (on) {
oldcode.setInputType(InputType.TYPE_CLASS_TEXT);
newcode.setInputType(InputType.TYPE_CLASS_TEXT);
renewcode.setInputType(InputType.TYPE_CLASS_TEXT);
}
else {
oldcode.setInputType(InputType.TYPE_CLASS_NUMBER);
newcode.setInputType(InputType.TYPE_CLASS_NUMBER);
renewcode.setInputType(InputType.TYPE_CLASS_NUMBER);
}
}
});
Any kind of help or suggestion is much appreciated.

Related

Textviews are not showing on real device

When app works fine
When app not shows textviews(its finding a sensor. When cant find, giving info on textview like 'didnt found')
I created a pedometer app. It was working well on my emulator and my own android device. But when ı publish that app my friends said textviews are invisible. I examined that problem in code but didnt found a problem. Textviews are getting their text from sensor. Writing steps and calories, after some calculating. Why that problem showed up? What is the source of this problem? Why is this happening?
<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"
xmlns:app="http://schemas.android.com/apk/res-auto"
tools:context="com.mbkdev.fragments.CountStepFragment"
android:background="#211D44"
><androidx.constraintlayout.widget.ConstraintLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
app:layout_constraintBottom_toTopOf="#+id/bottomNavigationView"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.5"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" >
<Button
android:id="#+id/btnstop"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginEnd="8dp"
android:layout_marginRight="8dp"
android:background="#drawable/roundedbtn"
android:text="Durdur"
android:textAllCaps="false"
android:textColor="#EBE9F1"
android:textSize="15sp"
android:textStyle="italic"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.781"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintVertical_bias="0.184" />
<Button
android:id="#+id/btnstart"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="#drawable/roundedbtn"
android:gravity="center"
android:text="Başlat"
android:textAllCaps="false"
android:textColor="#EBE9F1"
android:textSize="15sp"
android:textStyle="italic"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toStartOf="#+id/btnstop"
app:layout_constraintHorizontal_bias="0.472"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintVertical_bias="0.184" /></androidx.constraintlayout.widget.ConstraintLayout>
<TextView
android:id="#+id/txtStepCount"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textColor="#48B9AC"
android:layout_centerInParent="true" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#id/txtStepCount"
android:layout_margin="10dp"
android:textColor="#48B9AC"
android:layout_centerHorizontal="true"
android:text="Hedef: 10.000"
/>
<ProgressBar
android:id="#+id/progress_circular"
android:layout_width="250dp"
android:layout_height="250dp"
android:layout_centerInParent="true"
android:layout_gravity="center"
android:layout_marginTop="65dp"
android:indeterminateOnly="false"
android:progressDrawable="#drawable/circle"
android:rotation="-90"
tools:progress="60" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="200dp"
android:layout_below="#+id/progress_circular"
android:gravity="center"
android:orientation="horizontal"
>
<ImageView
android:id="#+id/imageView2"
android:layout_width="50dp"
android:layout_height="50dp"
android:layout_weight="1"
android:src="#drawable/cal"
android:layout_marginBottom="45dp"
android:layout_marginLeft="12dp"
/>
<ImageView
android:id="#+id/imageView3"
android:layout_width="50dp"
android:layout_height="50dp"
android:layout_weight="1"
android:src="#drawable/distance"
android:layout_marginRight="21dp"
android:layout_marginBottom="45dp"
android:layout_marginHorizontal="10dp"
/>
<ImageView
android:id="#+id/imageView"
android:layout_width="50dp"
android:layout_height="50dp"
android:src="#drawable/steps"
android:layout_weight="1"
android:layout_marginRight="15dp"
android:layout_marginBottom="45dp"
/>
</LinearLayout>
<LinearLayout
android:id="#+id/txtlinear"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="#+id/progress_circular"
android:gravity="center"
android:orientation="horizontal"
android:layout_marginTop="85dp"
>
<TextView
android:id="#+id/txtcalori_info"
android:layout_width="wrap_content"
android:layout_height="50dp"
android:text="Kalori: "
android:textSize="16sp"
android:textColor="#48B9AC"
android:layout_weight="1"
android:textStyle="italic"
android:layout_marginLeft="12dp"
android:layout_centerHorizontal="true"
android:layout_toLeftOf="#+id/txtdistanceinfo"
android:layout_below="#+id/progress_circular"
android:gravity="center_horizontal"
/>
<TextView
android:id="#+id/txtdistanceinfo"
android:layout_width="wrap_content"
android:layout_height="50dp"
android:textColor="#48B9AC"
android:layout_below="#+id/progress_circular"
android:layout_centerHorizontal="true"
android:gravity="center_horizontal"
android:layout_weight="1"
android:text="Mesafe: "
android:textSize="16sp"
android:textStyle="italic" />
<TextView
android:id="#+id/txtstepinfo"
android:layout_width="wrap_content"
android:layout_height="50dp"
android:gravity="center_horizontal"
android:layout_below="#+id/progress_circular"
android:layout_marginRight="12dp"
android:textColor="#48B9AC"
android:layout_weight="1"
android:layout_toRightOf="#+id/txtdistanceinfo"
android:text="Adım: "
android:textSize="16sp"
android:textStyle="italic" />
</LinearLayout>
My StepCounterFragment:
#Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
view = inflater.inflate(R.layout.fragment_count_step,container,false);
getActivity().getWindow().addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);
View view = inflater.inflate(R.layout.fragment_count_step, container, false);
textView = view.findViewById(R.id.txtStepCount);
txtstepinfo = view.findViewById(R.id.txtstepinfo);
txtcalinfo = view.findViewById(R.id.txtcalori_info);
txtDistanceinfo = view.findViewById(R.id.txtdistanceinfo);
btnStart = view.findViewById(R.id.btnstart);
btnStop = view.findViewById(R.id.btnstop);
progressBar = view.findViewById(R.id.progress_circular);
progressBar.setMax(10000);
btnStart.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
startService();
}
});
btnStop.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
getActivity().stopService(new Intent(getActivity(), StepCountService.class));
}
});
sharedPreferences = getActivity().getSharedPreferences("KEY", Context.MODE_PRIVATE);
editor = sharedPreferences.edit();
sensorManager = (SensorManager) getActivity().getSystemService(SENSOR_SERVICE);
if(sensorManager.getDefaultSensor(Sensor.TYPE_STEP_COUNTER) != null){
stepCounter = sensorManager.getDefaultSensor(Sensor.TYPE_STEP_COUNTER);
isCounterSensorPresent = true;
}
else{
textView.setText("Bulunamadı");
isCounterSensorPresent = false ;
}
System.out.println(stepCount);
return view;
}
#Override
public void onSensorChanged(SensorEvent sensorEvent) {
if (sensorEvent.sensor == stepCounter){
stepCount = (int) sensorEvent.values[0];
////////////////
saveSteps();
resetStep();
int stepNumb = sharedPreferences.getInt("step",0);
////////////////
progressBar.setProgress(stepNumb);
textView.setText(String.valueOf(stepNumb));
txtstepinfo.setText("Adım: " + String.valueOf(stepNumb) );
///////////
progressBar.setProgress(stepNumb);
Log.i("sda",String.valueOf(stepCount));
/////////////////////
txtcalinfo.setText("Kalori: "+calculateCalori(stepNumb));
txtDistanceinfo.setText("Mesafe: "+calculateDistance(stepNumb));
}
}
I think it's not one of programmatic issue and could be your listview went up to bottom on screen. You could research How to develop an android application for different device sizes. Visit here https://developer.android.com/training/multiscreen/screensizes
I found what is the problem. I was forgetting the add user permissions.
I Added to the Manifest.xml:
<uses-permission android:name="android.permission.ACTIVITY_RECOGNITION"/>
onCreate Method:
if(ContextCompat.checkSelfPermission(this,
Manifest.permission.ACTIVITY_RECOGNITION) == PackageManager.PERMISSION_DENIED){
//ask for permission
requestPermissions(new String[]{Manifest.permission.ACTIVITY_RECOGNITION}, PHYISCAL_ACTIVITY);
}

How do I send an email with filled subject and email address?

I wrote an activity to send an email in the app. However, i can't find a way to set the recipient and subject in the edittext fill. How should I set the email at the beginning ??
my activity
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_feedback_email);
emailAddress = (EditText) findViewById(R.id.email);
emailSubject = (EditText) findViewById(R.id.subject);
message = (EditText) findViewById(R.id.message);
sendEmailButton = (Button) findViewById(R.id.send_button);
sendEmailButton.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View view) {
String toemailAddress = emailAddress.getText().toString();
String msubject = emailSubject.getText().toString();
String mmessage = message.getText().toString();
Intent emailApp = new Intent(Intent.ACTION_SEND);
emailApp.putExtra(Intent.EXTRA_EMAIL, new String[]{toemailAddress});
emailApp.putExtra(Intent.EXTRA_SUBJECT, msubject);
emailApp.putExtra(Intent.EXTRA_TEXT, mmessage);
emailApp.setType("message/rfc822");
startActivity(Intent.createChooser(emailApp, "Send Email Via"));
}
});
}
my xml file
<TextView
android:id="#+id/textView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Subject"
android:textStyle="bold" />
<EditText
android:id="#+id/subject"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentEnd="true"
android:layout_alignParentRight="true"
android:layout_alignParentTop="true"
android:layout_toEndOf="#+id/textView3"
android:layout_toRightOf="#+id/textView3"
android:hint="Subject"
android:inputType="text" />
<TextView
android:id="#+id/textView2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:layout_below="#+id/textView"
android:layout_marginTop="43dp"
android:text="To"
android:textStyle="bold" />
<EditText
android:id="#+id/email"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentEnd="true"
android:layout_alignParentRight="true"
android:layout_alignTop="#+id/textView2"
android:layout_toEndOf="#+id/textView3"
android:layout_toRightOf="#+id/textView3"
android:hint="Email"
android:inputType="textEmailAddress" />
<TextView
android:id="#+id/textView3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:layout_below="#+id/email"
android:layout_marginTop="15dp"
android:text="Message:"
android:textStyle="bold" />
<EditText
android:id="#+id/message"
android:layout_width="wrap_content"
android:layout_height="150dp"
android:gravity="top"
android:hint="Your message here..."
android:inputType="textMultiLine"
android:layout_centerVertical="true"
android:layout_alignParentStart="true"
android:layout_alignEnd="#+id/email" />
<Button
android:id="#+id/send_button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="#498b24"
android:paddingTop="50dp"
android:padding="5dp"
android:text="Send Message "
android:textColor="#fff"
android:layout_alignParentBottom="true"
android:layout_centerHorizontal="true"
android:layout_marginBottom="46dp" />
How should I set the email at the beginning ??
I am not sure if this is what you want but you can set it in the xml as android:text="example#gmail.com" For example:
<EditText
android:id="#+id/email"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentEnd="true"
android:layout_alignParentRight="true"
android:layout_alignTop="#+id/textView2"
android:layout_toEndOf="#+id/textView3"
android:layout_toRightOf="#+id/textView3"
android:text="example#gmail.com"
android:inputType="textEmailAddress" />

Cannot find EditText from FragmentActivity

I am trying to save all the information entered from all EditTexts in each of my 3 Fragments. I am trying to get these information from an option button in my ActionBar.
I noticed that it cannot find the views when I am on a different tab.
My first fragment/ first tab:
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:tag="gen_info">
<LinearLayout android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:scrollbars="vertical">
<CheckBox
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Admin Account"
android:id="#+id/isAdmin" />
<EditText
android:id="#+id/code"
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:layout_marginTop="5dip"
android:singleLine="true"
android:hint="#string/code"
android:ems="10"
android:width="150dip" />
<EditText
android:id="#+id/name"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_marginTop="5dip"
android:singleLine="true"
android:hint="#string/fullname" />
<EditText
android:id="#+id/address"
android:layout_height="wrap_content"
android:layout_width="fill_parent"
android:hint="#string/address"
android:layout_marginTop="5dip" />
<EditText
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="5dip"
android:inputType="date"
android:ems="10"
android:id="#+id/birthdate"
android:hint="Birthdate (mm/dd/yyy)" />
<EditText
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="5dip"
android:inputType="number"
android:ems="10"
android:id="#+id/mobile"
android:hint="Mobile No" />
<EditText
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:inputType="number"
android:layout_marginTop="5dip"
android:ems="10"
android:id="#+id/workPhone"
android:hint="Work Phone" />
<EditText
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="5dip"
android:inputType="textEmailAddress"
android:ems="10"
android:id="#+id/email"
android:hint="Email" />
<Spinner
android:id="#+id/gender_options"
android:layout_marginTop="5dip"
android:layout_width="wrap_content"
android:layout_height="wrap_content"/>
<Spinner
android:id="#+id/civil_status"
android:layout_marginTop="5dip"
android:layout_width="wrap_content"
android:layout_height="wrap_content"/>
<EditText
android:layout_marginTop="5dip"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:inputType="date"
android:ems="10"
android:id="#+id/hired_date"
android:hint="Hired Date (mm/dd/yyyy)" />
<EditText
android:id="#+id/location"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_marginTop="5dip"
android:singleLine="true"
android:hint="Location" />
<Spinner
android:id="#+id/position"
android:layout_marginTop="5dip"
android:layout_marginBottom="5dip"
android:layout_width="wrap_content"
android:layout_height="wrap_content"/>
<Spinner
android:id="#+id/department"
android:layout_marginTop="5dip"
android:layout_marginBottom="5dip"
android:layout_width="wrap_content"
android:layout_height="wrap_content"/>
</LinearLayout>
My 2nd Fragment / tab
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:tag="contacts">
<LinearLayout android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:scrollbars="vertical">
<EditText
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:inputType="textPersonName"
android:ems="10"
android:id="#+id/contactName"
android:hint="Name"
android:paddingTop="5dip" />
<EditText
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:ems="10"
android:id="#+id/contactRelationship"
android:hint="Relationship"
android:paddingTop="5dip" />
<EditText
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:inputType="textPostalAddress"
android:ems="10"
android:id="#+id/contactAddress"
android:hint="Address"
android:paddingTop="5dip" />
<RelativeLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content">
<EditText
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:inputType="phone"
android:ems="10"
android:id="#+id/contactPhoneNo"
android:hint="Phone Number"
android:paddingTop="5dip" />
<Spinner
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/contactPhoneTypeSpinner"
android:layout_toEndOf="#+id/contactPhoneNo"
android:layout_toRightOf="#+id/contactPhoneNo"
android:paddingTop="5dip" />
</RelativeLayout>
<EditText
android:layout_width="match_parent"
android:layout_height="107dp"
android:inputType="textMultiLine"
android:ems="10"
android:id="#+id/contactSpecialNotes"
android:paddingTop="5dip"
android:hint="Write special notes here" />
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Add to list"
android:id="#+id/addContact" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="10dp"
android:layout_marginBottom="5dp"
android:layout_marginLeft="5dp"
android:textAppearance="?android:attr/textAppearanceLarge"
android:text="Contacts List"
android:id="#+id/contactsHeader"
android:editable="false" />
<TableLayout
android:id="#+id/contactsTableLayout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="5dp"
android:layout_marginRight="5dp"
android:paddingTop="5dip"></TableLayout>
</LinearLayout>
My 3rdfragment / tab:
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:tag="latest_wage">
<LinearLayout android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:scrollbars="vertical">
<EditText
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:inputType="date"
android:ems="10"
android:id="#+id/latestWageDate"
android:hint="Date" />
<EditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:inputType="textMultiLine"
android:ems="10"
android:id="#+id/latestWageNote"
android:hint="Note" />
<EditText
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:inputType="numberDecimal"
android:ems="10"
android:id="#+id/latestWageRate"
android:hint="Rate (PHP)" />
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Add Rate"
android:id="#+id/btnAddRate" />
<TableLayout
android:id="#+id/latestWageTableLayout"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:paddingTop="5dip"></TableLayout>
</LinearLayout>
I declared my first Fragment's elements here:
public static class LaunchpadSectionFragment extends Fragment {
#Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
View rootView = inflater.inflate(R.layout.fragment_section_launchpad, container, false);
Spinner spinner = (Spinner) rootView.findViewById(R.id.gender_options);
Spinner civilStatusSpinner = (Spinner) rootView.findViewById(R.id.civil_status);
Spinner positionSpinner = (Spinner) rootView.findViewById(R.id.position);
Spinner departmentSpinner = (Spinner) rootView.findViewById(R.id.department);
return rootView;
}
#Override
public void onActivityCreated(Bundle savedInstanceState) {
super.onActivityCreated(savedInstanceState);
}
}
Here's the function for my ActionBar:
#Override
public boolean onOptionsItemSelected(MenuItem item) {
switch (item.getItemId()) {
case android.R.id.home:
this.finish();
return true;
case R.id.action_save:
EditText code = (EditText) findViewById(R.id.code);
EditText name = (EditText) findViewById(R.id.name);
EditText address = (EditText) findViewById(R.id.address);
EditText birthDate = (EditText) findViewById(R.id.birthdate);
EditText mobile = (EditText) findViewById(R.id.mobile);
EditText workPhone = (EditText) findViewById(R.id.workPhone);
EditText email = (EditText) findViewById(R.id.email);
Spinner gender = (Spinner) findViewById(R.id.gender_options);
Spinner civilStatus = (Spinner) findViewById(R.id.civil_status);
EditText hiredDate = (EditText) findViewById(R.id.hired_date);
EditText location = (EditText) findViewById(R.id.location);
Spinner departmentId = (Spinner) findViewById(R.id.department);
CheckBox isAdmin = (CheckBox) findViewById(R.id.isAdmin);
return true;
case R.id.action_discard:
this.finish();
return true;
}
return super.onOptionsItemSelected(item);
}
All the Views would return null, these views are found on the first fragment. When I did not make the lat two fragments, I could find the views.
Any help would be greatly appreciated. Thanks!
On approach could be to handle your itemMenuClick in our Fragment itself. So you can handle them in your Fragment and get the Information you need: TUTORIAL
The other approach is to keep a Instance of all of your Fragments in your MainActivity globally and ask your Fragment for the values eg:
MainActivity:
Fragment1 _fragment1;
onCreate(..){
_fragment1 = new Fragment1();
}
onMenuItemSelected(....){
String test = _fragment1.getCustomText();
}
Fragment1:
EditText _test;
onCreate(...){
_test = _root.findViewById(R.id.et_test);
}
public String getCustomText(){
return _test.getText().toString();
}
Try given code
#Override
public boolean onOptionsItemSelected(MenuItem item) {
switch (item.getItemId()) {
case android.R.id.home:
this.finish();
return true;
case R.id.action_save:
EditText code = (EditText) getView().findViewById(R.id.code);
EditText name = (EditText) getView().findViewById(R.id.name);
EditText address = (EditText) getView().findViewById(R.id.address);
EditText birthDate = (EditText) getView().findViewById(R.id.birthdate);
EditText mobile = (EditText) getView().findViewById(R.id.mobile);
EditText workPhone = (EditText) getView().findViewById(R.id.workPhone);
EditText email = (EditText) getView().findViewById(R.id.email);
Spinner gender = (Spinner) getView().findViewById(R.id.gender_options);
Spinner civilStatus = (Spinner) getView().findViewById(R.id.civil_status);
EditText hiredDate = (EditText) getView().findViewById(R.id.hired_date);
EditText location = (EditText) getView().getView().findViewById(R.id.location);
Spinner departmentId = (Spinner) getView().findViewById(R.id.department);
CheckBox isAdmin = (CheckBox) getView().findViewById(R.id.isAdmin);
return true;
case R.id.action_discard:
this.finish();
return true;
}
return super.onOptionsItemSelected(item);
}

how to scroll up layout when clicking on edit text

this is my layout with soft input mode and without soft input mode.
But main problem is when i click next from second last edit text, i want to show those two buttons and last edit text with soft input mode. Please help
my xml file is as follows
<?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="fill_parent"
android:background="#drawable/scroll_bg" >
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="521dp"
android:layout_marginBottom="60dp"
android:background="#drawable/bg" >
<com.deemtech.widgets.MenuLayout
android:id="#+id/menuTitle"
android:layout_width="fill_parent"
android:layout_height="wrap_content" />
<TextView
android:id="#+id/txtCustomerDetails"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true"
android:layout_marginTop="140dp"
android:gravity="center"
android:text="#string/customer_details"
android:textColor="#ffffff"
android:textSize="12sp" />
<EditText
android:id="#+id/editNameCustomerDetails"
style="#style/EditText"
android:layout_below="#+id/txtCustomerDetails"
android:layout_centerHorizontal="true"
android:layout_marginTop="12dp"
android:ems="10"
android:hint="NAME"
android:inputType="text" />
<RelativeLayout
android:id="#+id/innerLayout"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_marginLeft="25dp"
android:layout_marginRight="25dp"
android:layout_marginTop="190dp"
android:background="#drawable/bg_create_account1x"
android:gravity="center"
android:paddingBottom="5dp"
android:paddingLeft="25dp"
android:paddingRight="25dp"
android:paddingTop="8dp" >
<EditText
android:id="#+id/editEmailCustomerDetails"
style="#style/EditText"
android:layout_alignLeft="#+id/editPhoneCutomerDetails"
android:layout_alignParentTop="true"
android:layout_marginTop="52dp"
android:ems="10"
android:hint="EMAIL ADDRESS"
android:inputType="textEmailAddress" />
<EditText
android:id="#+id/editPhoneCutomerDetails"
style="#style/EditText"
android:layout_below="#+id/editEmailCustomerDetails"
android:layout_marginTop="8dp"
android:ems="10"
android:hint="CONTACT NUMBER"
android:maxLength="12"
android:inputType="phone" />
<!--
<EditText
android:id="#+id/editAdditionalInfo"
android:layout_width="150dp"
android:layout_height="50dp"
android:layout_alignLeft="#+id/editPhoneCutomerDetails"
android:layout_alignRight="#+id/editPhoneCutomerDetails"
android:layout_below="#+id/editPhoneCutomerDetails"
android:layout_marginBottom="60dp"
android:layout_marginTop="10dp"
android:background="#drawable/message_additional_box1x"
android:ems="10"
android:hint="ADDITIONAL INFO"
android:inputType="text"
android:padding="10dp"
>
<requestFocus />
</EditText>
-->
<EditText
android:id="#+id/editAdditionalInfo"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignLeft="#+id/editPhoneCutomerDetails"
android:layout_alignParentBottom="true"
android:layout_alignRight="#+id/editPhoneCutomerDetails"
android:layout_below="#+id/editPhoneCutomerDetails"
android:layout_marginBottom="60dp"
android:layout_marginTop="8dp"
android:hint="ADDITIONAL INFO"
android:background="#drawable/message_additional_box1x"
android:ems="10"
android:singleLine="true"
android:gravity="top"
android:lines="3"
android:padding="10dp"
android:width="150dp" >
<requestFocus />
</EditText>
</RelativeLayout>
<Button
android:id="#+id/btnBackCustomerDetails"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="448dp"
android:layout_toLeftOf="#+id/btnSubmitCustomerDetails"
android:background="#drawable/btn_back"
android:contentDescription="#string/app_name" />
<Button
android:id="#+id/btnSubmitCustomerDetails"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignRight="#+id/editNameCustomerDetails"
android:layout_marginTop="448dp"
android:background="#drawable/btn_submit"
android:contentDescription="#string/app_name" />
</RelativeLayout>
</ScrollView>
In your case you cant simply "adjustResize" the window. Also as you only want to show the buttons when the last edit text is clicked.
So you can try this approach, not truly suggested but will work for your scenario:
#Override
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_mainf);
findViewById(R.id.editAdditionalInfo).setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
Toast.makeText(sampleMediaPlayer.this, "text", 700).show();
findViewById(R.id.btnBackCustomerDetails).requestFocusFromTouch();
findViewById(R.id.editAdditionalInfo).requestFocusFromTouch();
}
});
}
check this link
or try this android:windowSoftInputMode="adjustResize" in your activity in manifest file.
with the help of nimish's answer i finally got wat i wanted
editPhoneCustomerDetails.setOnKeyListener(new OnKeyListener() {
#Override
public boolean onKey(View v, int keyCode, KeyEvent event) {
if ((event.getAction() == KeyEvent.ACTION_DOWN) &&
(keyCode == KeyEvent.KEYCODE_ENTER)) {
findViewById(R.id.btnBackCustomerDetails).requestFocusFromTouch();
findViewById(R.id.editAdditionalInfo).requestFocusFromTouch();
//((ScrollView) findViewById(R.id.scrollView)).fullScroll(View.FOCUS_DOWN);
//findViewById(R.id.editPhoneCutomerDetails).requestFocusFromTouch();
// findViewById(R.id.btnBackCustomerDetails).requestFocusFromTouch();
}
return false;
}
});
findViewById(R.id.editAdditionalInfo).setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
//findViewById(R.id.btnBackCustomerDetails).setFocusable(true);
findViewById(R.id.btnBackCustomerDetails).requestFocusFromTouch();
findViewById(R.id.editAdditionalInfo).requestFocusFromTouch();
}
});

half or quarter black screen in android

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

Categories

Resources