créer un textView cliquable
Bonjour,
J'essaye de faire une action suite à un clique sur un TextView, mais il n'y a pas de réaction ! :(
Voici mon code
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20
|
...
<TextView
android:id="@+id/Champ_Adresse"
android:layout_width="match_parent"
android:layout_height="115dp"
android:background="#D67632"
android:clickable="true"
android:onClick="onClick"
android:text="Adresse"
android:textAppearance="?android:attr/textAppearanceLarge" />
<LinearLayout
android:id="@+id/layout_Adresse"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:visibility="gone" >
... |
java
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29
| public class new_client extends Activity {
@Override
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.new_client);
TextView t = (TextView)findViewById(R.id.Champ_Adresse);
t.setOnClickListener(new OnClickListener() {
public void onClick(View v) {
System.out.print("essai");
LinearLayout champ_adresse=(LinearLayout)findViewById(R.id.layout_Adresse);
int visibility_actuel = champ_adresse.getVisibility();
if(visibility_actuel==0){
champ_adresse.setVisibility(View.VISIBLE);
} else {
champ_adresse.setVisibility(View.GONE);
}// TODO Auto-generated method stub
}
});
}
} |
Merci pour votre aide
cedric