Hi I am working with android.I had created an app in which I had called second activity as intent and I make its background transparent.Second Activity contains a button and when click on it it shows a slidedrawer. After calling 2nd one I can view 1st activity because 2nd activity background is transparent.But How can I make an action even when the 2nd activity is also there ???
here is my code
1st activity
public class MainActivity5 extends Activity {
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.blah);
Button b1=(Button)findViewById(R.id.button1);
b1.setOnClickListener(new OnClickListener() {
#Override
public void onClick(View v) {
Intent intnt = new Intent(MainActivity5.this,
GestureActivity.class);
startActivity(intnt);
Toast.makeText(getApplicationContext(), "clicked", Toast.LENGTH_SHORT).show();
}
});
}
}
2nd activity
public class GestureActivity extends Activity {
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main1);
Toast.makeText(getApplicationContext(), "library", Toast.LENGTH_LONG).show();
}
}
activity_main1.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="wrap_content"
android:orientation="vertical"
style="#style/CustomTheme" >
<SlidingDrawer
android:id="#+id/drawer"
android:layout_width="330dip"
android:layout_height="450dip"
android:orientation="vertical"
android:content="#+id/content"
android:handle="#+id/handle" >
<ImageButton
android:id="#+id/handle"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="#drawable/ic_launcher"/>
<RelativeLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical"
android:background="#fe6e6e"
android:id="#+id/content">
<TextView
android:id="#+id/textView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Login Form"
android:layout_marginLeft="170px"
android:textColor="#101010"
android:textStyle="bold"
android:textSize="20sp"/>
<TextView
android:id="#+id/textView2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_below="#+id/textView1"
android:layout_marginLeft="30dp"
android:layout_marginTop="30dp"
android:text="User Name-"
android:textStyle="bold"
android:textColor="#480000"
android:textSize="18sp"/>
<EditText
android:id="#+id/userName"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignBaseline="#+id/textView2"
android:layout_alignBottom="#+id/textView2"
android:layout_marginLeft="40dp"
android:layout_toRightOf="#+id/textView2"
android:width="160px" >
</EditText>
<TextView
android:id="#+id/textView3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignLeft="#+id/textView2"
android:layout_below="#+id/userName"
android:layout_marginTop="44dp"
android:text="Password - "
android:textStyle="bold"
android:textColor="#480000"
android:textSize="18sp"/>
<EditText
android:id="#+id/password"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignBaseline="#+id/textView3"
android:layout_alignBottom="#+id/textView3"
android:layout_alignLeft="#+id/userName"
android:inputType="textPassword"
android:width="160px" >
</EditText>
<Button
android:id="#+id/login"
android:layout_width="130px"
android:layout_height="wrap_content"
android:layout_below="#+id/password"
android:layout_marginRight="25dp"
android:layout_marginTop="38dp"
android:layout_toLeftOf="#+id/password"
android:text="Login" />
<Button
android:id="#+id/reset"
android:layout_width="130px"
android:layout_height="wrap_content"
android:layout_alignBaseline="#+id/login"
android:layout_alignBottom="#+id/login"
android:layout_alignRight="#+id/password"
android:layout_marginRight="14dp"
android:text="Reset" />
</RelativeLayout>
</SlidingDrawer>
</LinearLayout>
is it possible to make both activity can run at the same time ???
No yaar you can't run both activities at the same time .You will get a clear idea about this if you know the activity lifecycle.
Below is the link which gives clear idea about activity lifecycle
http://developer.android.com/reference/android/app/Activity.html
Related
I have button on my activity that show up on the fragment and only the button that show up , i did search about it and find out its a rendering issue but the answers didn't worked for me, here how it looks.
Fragment
Activity
is there any chance that the issue code be from the margin of the button
Fragment.java
public class Smsar extends Fragment {
public Smsar() {
// Required empty public constructor
}
View root;
Button mSmsar,mFinder;
#Override
public View onCreateView(LayoutInflater inflater, final ViewGroup container,
Bundle savedInstanceState) {
// Inflate the layout for this fragment
root= inflater.inflate(R.layout.fragment_smsar, container, false);
mSmsar=(Button)root.findViewById(R.id.smsar);
mFinder=(Button)root.findViewById(R.id.finder);
mSmsar.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
getActivity().onBackPressed();
}
});
mFinder.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
//Open Discover.
}
});
return root;
}
}
Fragment XML
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#drawable/main_background_difference"
tools:context=".Smsar">
<!-- TODO: Update blank fragment layout -->
<Button
android:id="#+id/smsar"
android:layout_width="250dp"
android:layout_height="60dp"
android:layout_alignParentBottom="true"
android:layout_centerHorizontal="true"
android:layout_marginBottom="59dp"
android:background="#drawable/btn_rounded"
android:fontFamily="#font/cabin"
android:text="Smsar ?"
android:textAlignment="center"
android:textAllCaps="false"
android:textAppearance="#style/TextAppearance.AppCompat.Body1"
android:textSize="18sp"
android:typeface="normal" />
<Button
android:id="#+id/finder"
android:layout_width="204dp"
android:layout_height="63dp"
android:layout_alignParentBottom="true"
android:layout_centerHorizontal="true"
android:layout_marginBottom="138dp"
android:background="#drawable/btn_rounded"
android:fontFamily="#font/cabin"
android:text="Want Apartment ?"
android:textAppearance="#style/TextAppearance.AppCompat.Body1" />
</RelativeLayout>
Activity XML
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#drawable/background"
android:orientation="vertical"
tools:context=".MainActivity"
android:id="#+id/mainView"
>
<ImageView
android:id="#+id/logo"
android:layout_width="162dp"
android:layout_height="196dp"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true"
android:layout_marginTop="13dp"
android:adjustViewBounds="true"
android:maxHeight="64dp"
android:maxWidth="64dp"
app:srcCompat="#drawable/logo" />
<Button
android:id="#+id/logIn"
android:layout_width="218dp"
android:layout_height="wrap_content"
android:layout_alignEnd="#+id/userName"
android:layout_alignParentBottom="true"
android:layout_marginEnd="31dp"
android:layout_marginBottom="113dp"
android:background="#color/buttons"
android:clickable="true"
android:fontFamily="#font/catamaran"
android:onClick="logIN"
android:text="Login"
android:textAppearance="#style/TextAppearance.AppCompat.Body1"
android:textSize="22sp" />
<EditText
android:id="#+id/userName"
android:layout_width="277dp"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
android:ems="10"
android:fontFamily="#font/catamaran"
android:hint="UserName"
android:inputType="textPersonName"
android:text="" />
<EditText
android:id="#+id/password"
android:layout_width="277dp"
android:layout_height="wrap_content"
android:layout_below="#+id/userName"
android:layout_centerHorizontal="true"
android:fontFamily="#font/catamaran"
android:hint="Password"
android:inputType="textPassword" />
<TextView
android:id="#+id/_new"
android:layout_width="159dp"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_marginEnd="-35dp"
android:layout_marginBottom="0dp"
android:layout_toStartOf="#+id/sginUp"
android:fontFamily="#font/catamaran"
android:text="New ? Start Now By"
android:textAlignment="center"
android:textSize="18sp" />
<TextView
android:id="#+id/sginUp"
android:layout_width="81dp"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_marginStart="17dp"
android:layout_marginBottom="0dp"
android:layout_centerHorizontal="true"
android:layout_toEndOf="#id/mError"
android:clickable="true"
android:fontFamily="#font/catamaran"
android:text="SginUp"
android:textAlignment="center"
android:textColor="#color/links"
android:textSize="18sp" />
<TextView
android:id="#+id/mError"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_centerHorizontal="true"
android:layout_marginBottom="82dp"
android:textColor="#android:color/holo_red_dark"
android:visibility="invisible"
android:text="mError" />
</RelativeLayout>
Activity.Java
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
_login =(Button)findViewById(R.id.logIn);
pref = getSharedPreferences("user_details", MODE_PRIVATE);
if(pref.contains("username")&&pref.contains("password"))
success();
FragmentManager fm=getFragmentManager();
FragmentTransaction ft = fm.beginTransaction();
ft.addToBackStack(null);
ft.replace(R.id.mainView, mFrag);
ft.commit();
imageView=(ImageView)findViewById(R.id.logo);
mDBHelper =new DBHelper(this);
mError=(TextView)findViewById(R.id.mError);
//Define the variables
userNameEdit=(EditText)findViewById(R.id.userName);
passwordEdit=(EditText)findViewById(R.id.password);
_signUp=(TextView)findViewById(R.id.sginUp);
//End
_signUp.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
intent=new Intent(MainActivity.this,Signup.class);
startActivity(intent);
}
});
}
I solve it by surround the button with LinearLayout
<LinearLayout
android:id="#+id/buttonContainer"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#id/password"
android:layout_marginTop="10dp"
android:layout_centerHorizontal="true"
android:layout_centerVertical="true"
>
<Button
android:id="#+id/logIn"
android:layout_width="186dp"
android:layout_height="wrap_content"
android:layout_marginVertical="12dp"
android:background="#drawable/btn_rounded"
android:minWidth="200dp"
android:onClick="logIN"
android:text="#string/title_login"
android:textAllCaps="false"
android:textColor="#color/ms_white"
android:textSize="18sp" />
</LinearLayout>
I'm an Android beginner and I have a little problem.
I have 2 radioButtons titled "Yes" and "No", 4 editTexts which are disabled and a button titled "Reset All".
Now, when I select the "No" radioButton, editTexts 1 and 2 become enabled and 1 gains focus. This is the desired behaviour. But When I select "Reset All" and again repeat the procedure, only editText 2 gets enabled and the "No" radioButton is still unchecked.
Following is my code:
MainActivity.java
package com.example.chris.myapplication;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.RadioButton;
public class MainActivity extends AppCompatActivity {
EditText e1;
EditText e2;
EditText e3;
EditText e4;
RadioButton yes;
RadioButton no;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
e1 = (EditText)findViewById(R.id.e1);
e2 = (EditText)findViewById(R.id.e2);
e3 = (EditText)findViewById(R.id.e3);
e4 = (EditText)findViewById(R.id.e4);
yes = (RadioButton)findViewById(R.id.yes);
no = (RadioButton)findViewById(R.id.no);
}
public void onClickreset(View v){
yes.setChecked(false);
no.setChecked(false);
e1.setEnabled(false);
e2.setEnabled(false);
e3.setEnabled(false);
e1.setText("");
e2.setText("");
e3.setText("");
e4.setText("");
};
public void onRadioButtonClicked(View v)
{
boolean checked = ((RadioButton) v).isChecked();
switch(v.getId()){
case R.id.yes:
if(checked)
e1.setEnabled(false);
e2.setEnabled(false);
e3.setEnabled(true);
e3.requestFocus();
break;
case R.id.no:
if(checked)
e1.setEnabled(true);
e2.setEnabled(true);
e2.requestFocus();
e2.clearFocus();
e3.setEnabled(false);
break;
}
}
}
activity_main.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:id="#+id/LL"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
tools:context="com.example.chris.myapplication.MainActivity">
<TableLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:shrinkColumns="*"
android:stretchColumns="*">
<!-- Row 1 Starts From Here -->
<TableRow
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:gravity="center_horizontal">
<RadioGroup
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_span="3"
android:gravity="center"
android:orientation="horizontal">
<RadioButton
android:id="#+id/yes"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="1dp"
android:checked="false"
android:onClick="onRadioButtonClicked"
android:text="yes" />
<RadioButton
android:id="#+id/no"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="4dp"
android:checked="false"
android:onClick="onRadioButtonClicked"
android:text="no" />
</RadioGroup>
</TableRow>
<TableRow
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:gravity="center_horizontal">
<TextView
android:id="#+id/t1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:paddingLeft="10dp"
android:text="1:"
android:textColor="#000000" />
<EditText
android:id="#+id/e1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:ems="10"
android:enabled="false"
android:inputType="numberDecimal"
android:textColor="#000000" />
</TableRow>
<TableRow
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:gravity="center_horizontal">
<TextView
android:id="#+id/t2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:paddingLeft="10dp"
android:text="2:"
android:textColor="#000000" />
<EditText
android:id="#+id/e2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:ems="10"
android:enabled="false"
android:inputType="numberDecimal"
android:textColor="#000000" />
</TableRow>
<TableRow
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:gravity="center_horizontal">
<TextView
android:id="#+id/t3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:paddingLeft="10dp"
android:text="3:"
android:textColor="#000000" />
<EditText
android:id="#+id/e3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:ems="10"
android:enabled="false"
android:inputType="numberDecimal"
android:textColor="#000000" />
</TableRow>
<TableRow
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:gravity="center_horizontal">
<TextView
android:id="#+id/t4"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:paddingLeft="10dp"
android:text="4:"
android:textColor="#000000" />
<EditText
android:id="#+id/e4"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:ems="10"
android:enabled="false"
android:inputType="numberDecimal"
android:textColor="#000000" />
</TableRow>
<TableRow
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="center_horizontal"
android:paddingTop="30dp" />
<Button
android:id="#+id/reset"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_span="3"
android:gravity="center"
android:onClick="onClickreset"
android:text="Reset"
android:textAllCaps="false"
android:textColor="#000000"
android:textStyle="normal" />
</TableLayout>
</LinearLayout>
It's better to use RadioGroup.OnCheckedChangeListener, first of all, get rid of android:onClick attributes and assign an id to RadioGroup in XML:
<RadioGroup
android:id="#+id/yes_no_radio_group"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_span="3"
android:gravity="center"
android:orientation="horizontal">
<RadioButton
android:id="#+id/yes"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="1dp"
android:checked="false"
android:text="yes" />
<RadioButton
android:id="#+id/no"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="4dp"
android:checked="false"
android:text="no" />
</RadioGroup>
Then make your Activity implements RadioGroup.OnCheckedChangeListener and move there code from onRadioButtonClicked(View v) method:
public class MainActivity extends AppCompatActivity implements RadioGroup.OnCheckedChangeListener {
//Some activity code
#Override
public void onCheckedChanged(RadioGroup radioGroup, int i) {
switch (radioGroup.getCheckedRadioButtonId()) {
case R.id.yes: //Not needed to
e1.setEnabled(false); //which RadioButton clicked
e2.setEnabled(false);
e3.setEnabled(true);
e3.requestFocus();
break;
case R.id.no:
e1.setEnabled(true);
e2.setEnabled(true);
e2.requestFocus();
e2.clearFocus();
e3.setEnabled(false);
break;
}
}
}
Then, assign OnCheckedChangeListener with RadioGroup:
yesNoGroup = findViewById(R.id.radio_group);
yesNoGroup.setOnCheckedChangeListener(this);
And change:
yes.setChecked(false);
no.setChecked(false);
To
yesNoGroup.clearCheck();
Hello I am developing an application android, I have a problem with a text view that retrieves the data via web service, the data retrieve appears but infringe on the other text view of the page, Here is my code from my xml page:
<?xml version="1.0" encoding="utf-8"?>
<TextView
android:id="#+id/tvd"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true"
android:text="Détail de l'établissement"
android:textSize="20dp"
android:textStyle="bold"/>
<TextView
android:id="#+id/textView3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="42dp"
android:text="Libelle :"
android:textSize="20dp"
android:textStyle="bold"
android:layout_below="#+id/tvd"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true" />
<TextView
android:id="#+id/textView4"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="64dp"
android:text="Code postal :"
android:textSize="20dp"
android:textStyle="bold"
android:layout_below="#+id/textView3"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true" />
<TextView
android:id="#+id/textView5"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="64dp"
android:text="Ville :"
android:textSize="20dp"
android:textStyle="bold"
android:layout_below="#+id/textView4"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true" />
<TextView
android:id="#+id/tvl"
android:layout_width="200dp"
android:layout_height="wrap_content"
android:layout_alignTop="#+id/textView3"
android:layout_alignParentEnd="true"
android:hint="libelle"
android:textSize="20dp"
/>
<TextView
android:id="#+id/tvcp"
android:layout_width="200dp"
android:layout_height="wrap_content"
android:layout_alignLeft="#+id/tvl"
android:layout_alignStart="#+id/tvl"
android:layout_alignTop="#+id/textView4"
android:hint="Code postal"
android:textSize="20dp" />
<TextView
android:id="#+id/tvv"
android:layout_width="200dp"
android:layout_height="wrap_content"
android:layout_alignLeft="#+id/tvcp"
android:layout_alignStart="#+id/tvcp"
android:layout_alignTop="#+id/textView5"
android:hint="Ville"
android:textSize="20dp" />
<Button
android:id="#+id/btnMa"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_centerHorizontal="true"
android:text="Matériel numérique associé"
android:textSize="20dp"
android:textStyle="bold|italic"
/>
<TextView
android:id="#+id/textView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:textSize="20dp"
android:textStyle="bold"
android:layout_below="#+id/textView5"
android:layout_marginTop="39dp"
android:text="Présentation" />
<TextView
android:id="#+id/tvp"
android:layout_width="200dp"
android:layout_height="wrap_content"
android:layout_alignBottom="#+id/textView"
android:layout_alignLeft="#+id/tvv"
android:layout_alignStart="#+id/tvv"
android:hint="Presentation"
android:textSize="20dp" />
Then my code that says or go data :
public class DetailEtab extends Activity {
private TextView tv;
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.etabdetail);
tv = (TextView) findViewById(R.id.tvl);
tv.setText(search_ville.etabSELECT.getLibelle());
tv = (TextView) findViewById(R.id.tvcp);
tv.setText(search_ville.etabSELECT.getCp());
tv = (TextView) findViewById(R.id.tvv);
tv.setText(search_ville.etabSELECT.getVille());
tv = (TextView) findViewById(R.id.tvp);
tv.setText(search_ville.etabSELECT.getPresentation());
Button btnSa = (Button) findViewById(R.id.btnMa);
btnSa.setOnClickListener(new Button.OnClickListener() {
#Override
public void onClick(View v) {
Intent intent = new Intent(DetailEtab.this, MaterielAssocie.class);
startActivity(intent);
Log.i("ETAB", "servcies associes");
Toast toast = Toast.makeText(getApplicationContext(), "services associes", Toast.LENGTH_SHORT);
toast.show();
}
});
}
}
If anyone can tell me why it does that thanks
[screenshot][1] [1]: https://i.stack.imgur.com/ImHxk.png
You have problems with your layouts. I recommend you to wrap every line into separate LinearLayout and then use LinearLayout to wrap all new LinearLayouts. Also due to long text it's better to wrap parent LinearLayout into Scroll.
NOTE: This is just example that was written inside text box that simply shows main idea and may contain mistakes
Something like this:
<?xml version="1.0" encoding="utf-8"?>
<ScrollView
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<LinearLayout
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="wrap_content">
<TextView
android:id="#+id/tvd"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="Détail de l'établissement"
android:textSize="20dp"
android:textStyle="bold"/>
<LinearLayout
android:orientation="horizontal"
android:layout_width="fill_parent"
android:layout_height="wrap_content">
<TextView
android:id="#+id/textView3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="42dp"
android:text="Libelle :"
android:textSize="20dp"
android:textStyle="bold"
/>
<TextView
android:id="#+id/tvl"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:hint="libelle"
android:textSize="20dp"
/>
</LinearLayout>
<LinearLayout
android:orientation="horizontal"
android:layout_width="fill_parent"
android:layout_height="wrap_content">
<TextView
android:id="#+id/textView4"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="64dp"
android:text="Code postal :"
android:textSize="20dp"
android:textStyle="bold" />
<TextView
android:id="#+id/tvcp"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:hint="Code postal"
android:textSize="20dp" />
</LinearLayout>
<LinearLayout
android:orientation="horizontal"
android:layout_width="fill_parent"
android:layout_height="wrap_content">
<TextView
android:id="#+id/textView5"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="64dp"
android:text="Ville :"
android:textSize="20dp"
android:textStyle="bold" />
<TextView
android:id="#+id/tvv"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:hint="Ville"
android:textSize="20dp" />
</LinearLayout>
<LinearLayout
android:orientation="horizontal"
android:layout_width="fill_parent"
android:layout_height="wrap_content">
<TextView
android:id="#+id/textView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="20dp"
android:textStyle="bold"
android:layout_marginTop="39dp"
android:text="Présentation" />
<TextView
android:id="#+id/tvp"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:hint="Presentation"
android:textSize="20dp" />
</LinearLayout>
<Button
android:id="#+id/btnMa"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="Matériel numérique associé"
android:textSize="20dp"
android:textStyle="bold|italic"
/>
</LinearLayout>
</ScrollView>
You are assigning tv to multiple different TextViews and then you are assigning multiple values to the last TextView you assign it to.
public class DetailEtab extends Activity {
private TextView tv,tv1,tv2,tv3;
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.etabdetail);
tv = (TextView) findViewById(R.id.tvl);
tv.setText(search_ville.etabSELECT.getLibelle());
tv1 = (TextView) findViewById(R.id.tvcp);
tv1.setText(search_ville.etabSELECT.getCp());
tv2 = (TextView) findViewById(R.id.tvv);
tv2.setText(search_ville.etabSELECT.getVille());
tv3 = (TextView) findViewById(R.id.tvp);
tv3.setText(search_ville.etabSELECT.getPresentation());
Button btnSa = (Button) findViewById(R.id.btnMa);
btnSa.setOnClickListener(new Button.OnClickListener() {
#Override
public void onClick(View v) {
Intent intent = new Intent(DetailEtab.this, MaterielAssocie.class);
startActivity(intent);
Log.i("ETAB", "servcies associes");
Toast toast = Toast.makeText(getApplicationContext(), "services associes", Toast.LENGTH_SHORT);
toast.show();
}
});
}
}
Try this layout:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="wrap_content" android:layout_height="wrap_content">
<TextView
android:id="#+id/tvd"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true"
android:text="Détail de l'établissement"
android:textSize="20dp"
android:textStyle="bold"/>
<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/tvd"
android:layout_marginTop="42dp"
android:text="Libelle :"
android:textSize="20dp"
android:textStyle="bold"/>
<TextView
android:id="#+id/textView4"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:layout_below="#+id/textView3"
android:layout_marginTop="64dp"
android:text="Code postal :"
android:textSize="20dp"
android:textStyle="bold"/>
<TextView
android:id="#+id/textView5"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:layout_below="#+id/textView4"
android:layout_marginTop="64dp"
android:text="Ville :"
android:textSize="20dp"
android:textStyle="bold"/>
<TextView
android:id="#+id/tvl"
android:layout_width="200dp"
android:layout_height="80dp"
android:layout_alignParentEnd="true"
android:text="hfdgsjfhgadsjfgajsdfhgggdsjfgsdjafhgjsdafhgjdhfgjsdhgfjdshfgjdshfgjhdgfjdshgfjhdgfjsdhgafjahgsdfjdshgfjhdsagfjhdsgafjhsdagfjhdsgafjhsadgfjfdgjshfgjhfgjhsdgfhsgdfjhdsgfjhgdsjfhgsdjfhgsdjfhgsdjfhgsdjfhgsdjfhgsdjhfgjsdhgfjsdhgfjsdhfgjsdhfgjdsfhgjsdhgfjdshgfjsdhgfjhsgdfjhsdgjfhdgfjhgdsf"
android:layout_alignTop="#+id/textView3"
android:hint="libelle"
android:textSize="20dp"
/>
<TextView
android:id="#+id/tvcp"
android:layout_width="200dp"
android:layout_height="80dp"
android:layout_alignLeft="#+id/tvl"
android:layout_alignStart="#+id/tvl"
android:layout_alignTop="#+id/textView4"
android:hint="Code postal"
android:text="hfdgsjfhgadsjfgajsdfhgggdsjfgsdjafhgjsdafhgjdhfgjsdhgfjdshfgjdshfgjhdgfjdshgfjhdgfjsdhgafjahgsdfjdshgfjhdsagfjhdsgafjhsdagfjhdsgafjhsadgfjfdgjshfgjhfgjhsdgfhsgdfjhdsgfjhgdsjfhgsdjfhgsdjfhgsdjfhgsdjfhgsdjfhgsdjhfgjsdhgfjsdhgfjsdhfgjsdhfgjdsfhgjsdhgfjdshgfjsdhgfjhsgdfjhsdgjfhdgfjhgdsf"
android:textSize="20dp"/>
<TextView
android:id="#+id/tvv"
android:layout_width="200dp"
android:layout_height="80dp"
android:layout_alignLeft="#+id/tvcp"
android:layout_alignStart="#+id/tvcp"
android:layout_alignTop="#+id/textView5"
android:text="hfdgsjfhgadsjfgajsdfhgggdsjfgsdjafhgjsdafhgjdhfgjsdhgfjdshfgjdshfgjhdgfjdshgfjhdgfjsdhgafjahgsdfjdshgfjhdsagfjhdsgafjhsdagfjhdsgafjhsadgfjfdgjshfgjhfgjhsdgfhsgdfjhdsgfjhgdsjfhgsdjfhgsdjfhgsdjfhgsdjfhgsdjfhgsdjhfgjsdhgfjsdhgfjsdhfgjsdhfgjdsfhgjsdhgfjdshgfjsdhgfjhsgdfjhsdgjfhdgfjhgdsf"
android:hint="Ville"
android:textSize="20dp"/>
<Button
android:id="#+id/btnMa"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_centerHorizontal="true"
android:text="Matériel numérique associé"
android:textSize="20dp"
android:textStyle="bold|italic"
/>
<TextView
android:id="#+id/textView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:layout_below="#+id/textView5"
android:layout_marginTop="39dp"
android:text="Présentation"
android:textSize="20dp"
android:textStyle="bold"/>
<TextView
android:id="#+id/tvp"
android:layout_width="200dp"
android:layout_height="80dp"
android:layout_below="#+id/tvv"
android:layout_toRightOf="#id/textView"
android:layout_alignLeft="#+id/tvv"
android:layout_alignStart="#+id/tvv"
android:text="hfdgsjfhgadsjfgajsdfhgggdsjfgsdjafhgjsdafhgjdhfgjsdhgfjdshfgjdshfgjhdgfjdshgfjhdgfjsdhgafjahgsdfjdshgfjhdsagfjhdsgafjhsdagfjhdsgafjhsadgfjfdgjshfgjhfgjhsdgfhsgdfjhdsgfjhgdsjfhgsdjfhgsdjfhgsdjfhgsdjfhgsdjfhgsdjhfgjsdhgfjsdhgfjsdhfgjsdhfgjdsfhgjsdhgfjdshgfjsdhgfjhsgdfjhsdgjfhdgfjhgdsf"
android:hint="Presentation"
android:textSize="20dp"/>
</RelativeLayout>
My application is working successfully in Android 2.x to 4.1.x
In Google TV emulator i am running my existing application.
Google TV is not support touch input, So user must use navigation flow like move left, move right, move top and move bottom.
But this control can not point on ImageButton control.
How can reach my pointer for operate ImageButton.?
XML Layout :
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/mainLayout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#drawable/background" >
<TextView
android:id="#+id/headingTextView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_marginTop="20dip"
android:gravity="center_horizontal"
android:text="Kit - Device Registration"
android:textSize="75sp" />
<RelativeLayout
android:id="#+id/kitDetailsRelativeLayout"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#+id/headingTextView"
android:layout_centerInParent="true"
android:layout_marginTop="100dp" >
<TextView
android:id="#+id/WebURLTextView"
android:layout_width="250dp"
android:layout_height="wrap_content"
android:layout_marginTop="30dp"
android:gravity="right"
android:text="Web Url:"
android:textSize="50dp" />
<EditText
android:id="#+id/WebURLEditText"
style="#style/EditTextStyle"
android:layout_width="700dp"
android:layout_height="wrap_content"
android:layout_marginLeft="60dp"
android:layout_marginTop="30dp"
android:layout_toRightOf="#id/WebURLTextView"
android:hint="Enter Web Url"
android:text=""
android:textSize="40dp" />
<TextView
android:id="#+id/KitNoTextView"
android:layout_width="250dp"
android:layout_height="wrap_content"
android:layout_alignLeft="#id/WebURLTextView"
android:layout_below="#id/WebURLEditText"
android:layout_marginTop="5dp"
android:gravity="right"
android:text="KIT No:"
android:textSize="50dp" />
<EditText
android:id="#+id/KitNoEditText"
style="#style/EditTextStyle"
android:layout_width="700dp"
android:layout_height="wrap_content"
android:layout_below="#id/WebURLTextView"
android:layout_marginLeft="60dp"
android:layout_marginTop="10dp"
android:layout_toRightOf="#id/KitNoTextView"
android:hint="Enter KIT No"
android:textSize="40dp" />
<TextView
android:id="#+id/UniqueIdTextView"
android:layout_width="250dp"
android:layout_height="wrap_content"
android:layout_alignLeft="#id/WebURLTextView"
android:layout_below="#id/KitNoEditText"
android:layout_marginTop="5dp"
android:gravity="right"
android:text="Unique Id:"
android:textSize="50dp" />
<EditText
android:id="#+id/UniqueIdEditText"
android:layout_width="700dp"
android:layout_height="wrap_content"
android:layout_below="#id/KitNoTextView"
android:layout_marginLeft="60dp"
android:layout_marginTop="10dp"
android:layout_toRightOf="#id/UniqueIdTextView"
android:editable="false"
android:focusable="false"
android:textSize="40dp" />
<Button
android:id="#+id/ih_comBtn"
android:layout_width="wrap_content"
android:layout_height="72dp"
android:layout_above="#+id/KitNoTextView"
android:layout_toRightOf="#+id/WebURLEditText"
android:text="#string/lbl_host_name"
android:textSize="35sp" />
</RelativeLayout>
<ImageView
android:id="#+id/topSettingsIcon"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_alignParentTop="true"
android:layout_marginRight="10dip"
android:layout_marginTop="10dip"
android:background="#drawable/streak_settings" />
<RelativeLayout
android:id="#+id/kitControlRelativeLayout"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_centerHorizontal="true"
android:layout_marginBottom="10dp" >
<ImageButton
android:id="#+id/quitBtn"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:background="#drawable/quit_button" />
<ImageButton
android:id="#+id/verifyBtn"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignTop="#id/quitBtn"
android:layout_marginRight="20dip"
android:layout_toLeftOf="#id/quitBtn"
android:background="#drawable/register_button" />
<ImageButton
android:id="#+id/clearBtn"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignTop="#id/quitBtn"
android:layout_marginLeft="20dip"
android:layout_toRightOf="#id/quitBtn"
android:background="#drawable/clear_button" />
</RelativeLayout>
</RelativeLayout>
Java File Code :
import android.os.Bundle;
//Other Imports
public class <classs Name> extends Activity {
EditText webUrlEditTextObj;
EditText uniqueIdEditTextObj;
/**
* Refers to Register image button
*/
private ImageButton registerBtnObj;
/**
* Refers to Quit image button
*/
private ImageButton quitBtnObj;
/**
* Refers to Clear image button
*/
private ImageButton clearBtnObj;
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
WindowManager.LayoutParams.FLAG_FULLSCREEN);
setContentView(R.layout.<XML file Name>);
//...
registerBtnObj = (ImageButton) findViewById(R.id.verifyBtn);
quitBtnObj = (ImageButton) findViewById(R.id.quitBtn);
clearBtnObj = (ImageButton) findViewById(R.id.clearBtn);
verifyBtnObj.setOnClickListener(verifyListener);
quitBtnObj.setOnClickListener(quitListener);
clearBtnObj.setOnClickListener(clearListener);
//...
}
/**
* Listener for Register button click.
*/
private OnClickListener verifyListener = new OnClickListener() {
public void onClick(View v) {
/**
* Block of code
*/
}
};
/**
* Listener for Quit button click.
*/
private OnClickListener quitListener = new OnClickListener() {
public void onClick(View v) {
/**
* Block of code
*/
}
};
/**
* Listener for Clear button click.
*/
private OnClickListener clearListener = new OnClickListener() {
public void onClick(View v) {
/**
* Block of code
*/
}
};
}
Make sure your ImageButtons are marked as focusable. You'll also want to make sure you set the nextFocus* related attributes as well. The following is from my project, Serenity for Android which uses ImageButtons on the OSD when playing a video.
<ImageButton
android:id="#+id/osd_rewind_control"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="#android:color/transparent"
android:focusable="true"
android:nextFocusRight="#+id/mediacontroller_play_pause"
android:nextFocusUp="#+id/mediacontroller_seekbar"
android:scaleType="fitXY"
style="#android:style/MediaButton.Rew"
android:src="#drawable/skipback_selector"
tools:ignore="ContentDescription" />
Again make sure you set the android:focusable to true. All source code for my app is available to look at as well.
https://github.com/NineWorlds/serenity-android/blob/master/serenity-app/res/layout-large/serenity_media_controller.xml
I have a very simple MainActivity, and from that Activity I start the other Activity (with theme Dialog so it floats on top of the MainActivity.
The problem is that there is always a delay before the second Activity show up. I'd say it takes almost 1 second for it to show, and there is no code at all in second Activity. The only code in the second Activity is this:
package MyPackage;
import android.app.Activity;
import android.os.Bundle;
import android.widget.ArrayAdapter;
import android.widget.ListView;
import android.widget.TextView;
public class JobViewActivity extends Activity {
#Override
protected void onCreate(android.os.Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.jobview);
}
#Override
protected void onResume() {
super.onResume();
}
}
The MainActivity has a ListView with Nodes, and there is a click listener connected to the ListView in the onCreate like this:
public void onCreate(Bundle savedInstanceState)
{
requestWindowFeature(Window.FEATURE_NO_TITLE);
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
_nodeRowAdapter = new NodeRowAdapter(this, _nodes);
listView = (ListView)findViewById(R.id.ListViewNodes);
listView.setAdapter(_nodeRowAdapter);
listView.setOnItemClickListener(new OnItemClickListener() {
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
Intent i = new Intent(getApplicationContext(), JobViewActivity.class);
startActivity(i);
}
});
But when the ListItem is pressed, and the Click listener is triggered, it takes about 1 second to show the "popup".
The layout isn't very advanced in the popup. Here is the layout:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent" android:weightSum="1"
android:stretchColumns="1" android:orientation="vertical">
<TableLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:stretchColumns="1" android:layout_height="wrap_content" android:id="#+id/tableLayout1">
<TableRow>
<TextView
android:text="Id: "
android:padding="10dip"/>
<TextView
android:text="Ext id: "
android:gravity="right"
android:padding="10dip" />
</TableRow>
</TableLayout>
<RelativeLayout android:layout_width="fill_parent" android:layout_height="wrap_content" android:layout_alignParentBottom="true" android:id="#+id/relativeLayout1">
<LinearLayout android:id="#+id/linearLayout1" android:layout_width="fill_parent" android:layout_height="wrap_content" android:background="#E7F3F1">
<Button android:text="Start" android:id="#+id/button1" style="#style/ButtonText" android:layout_weight="1" android:background="#drawable/button_green"></Button>
<Button android:text="Bom" android:id="#+id/button2" style="#style/ButtonText" android:layout_weight="1" android:background="#drawable/button_red"></Button>
<Button android:text="Mer" android:id="#+id/button3" style="#style/ButtonText" android:layout_weight="1" android:background="#drawable/button_yellow"></Button>
<Button android:text="Nav" android:id="#+id/button4" style="#style/ButtonText" android:layout_weight="1"></Button>
</LinearLayout>
</RelativeLayout>
<RelativeLayout android:layout_height="fill_parent" android:layout_width="fill_parent" android:layout_below="#+id/tableLayout1" android:layout_alignParentLeft="true" android:layout_above="#+id/relativeLayout1" android:padding="6dip">
<TextView style="#style/JobViewHeader" android:id="#+id/textView1" android:text="Something: "></TextView>
<TextView style="#style/JobViewHeader" android:id="#+id/TextView2" android:text="Something: " android:layout_below="#+id/textView1"></TextView>
<TextView style="#style/JobViewHeader" android:id="#+id/TextView3" android:layout_marginTop="16dp" android:text="Kund: " android:layout_below="#+id/TextView2"></TextView>
<TextView style="#style/JobViewHeader" android:id="#+id/TextView4" android:text="Something: " android:layout_below="#+id/TextView3"></TextView>
<TextView style="#style/JobViewHeader" android:id="#+id/TextView5" android:text="Something: " android:layout_below="#+id/TextView4"></TextView>
<TextView style="#style/JobViewHeader" android:id="#+id/TextView6" android:text="Something: " android:layout_below="#+id/TextView5"></TextView>
<TextView style="#style/JobViewHeader" android:id="#+id/TextView7" android:text="Something: " android:layout_below="#+id/TextView6"></TextView>
<TextView style="#style/JobViewHeader" android:id="#+id/TextView8" android:layout_marginTop="20dp" android:text="Something: " android:layout_below="#+id/TextView7"></TextView>
<TextView android:layout_height="wrap_content" android:text="TextView" android:layout_width="wrap_content" android:layout_alignBaseline="#+id/textView1" android:layout_alignBottom="#+id/textView1" android:layout_toRightOf="#+id/textView1" android:id="#+id/textViewPickuptime"></TextView>
<TextView android:layout_height="wrap_content" android:text="TextView" android:layout_width="wrap_content" android:layout_alignBaseline="#+id/TextView2" android:layout_alignBottom="#+id/TextView2" android:layout_toRightOf="#+id/TextView2" android:id="#+id/textViewPickupAddress"></TextView>
<TextView android:layout_height="wrap_content" android:text="TextView" android:layout_width="wrap_content" android:layout_above="#+id/TextView4" android:layout_toRightOf="#+id/TextView3" android:id="#+id/textViewCustomer"></TextView>
<TextView android:layout_height="wrap_content" android:text="TextView" android:layout_width="wrap_content" android:layout_alignBaseline="#+id/TextView4" android:layout_alignBottom="#+id/TextView4" android:layout_toRightOf="#+id/TextView4" android:id="#+id/textViewNbrOfPassengers"></TextView>
<TextView android:layout_height="wrap_content" android:text="TextView" android:layout_width="wrap_content" android:layout_above="#+id/TextView6" android:layout_toRightOf="#+id/TextView5" android:id="#+id/textViewRoutine"></TextView>
<TextView android:layout_height="wrap_content" android:text="TextView" android:layout_width="wrap_content" android:layout_alignBaseline="#+id/TextView6" android:layout_alignBottom="#+id/TextView6" android:layout_toRightOf="#+id/TextView6" android:id="#+id/textViewServiceFee"></TextView>
<TextView android:layout_height="wrap_content" android:text="TextView" android:layout_width="wrap_content" android:layout_alignBaseline="#+id/TextView7" android:layout_alignBottom="#+id/TextView7" android:layout_toRightOf="#+id/TextView7" android:id="#+id/textViewHelp"></TextView>
<TextView android:layout_height="wrap_content" android:text="TextView" android:layout_width="wrap_content" android:layout_below="#+id/TextView8" android:layout_alignLeft="#+id/TextView8" android:id="#+id/textViewExtra"></TextView>
</RelativeLayout>
</RelativeLayout>
Im not sure what else to tell you, there isnt much more too it.
Im testing on a device, Samsung Galaxy S2.