Dernier
Tp Android
I/ ListView :
a)Layout
XML :
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical"
>
<ListView
android:id="@+id/android:list"
android:layout_width="fill_parent"
android:layout_height="wrap_content"></ListView>
</LinearLayout>
b)Activity :
public
class
Tp2Activity extends
ListActivity {
static
final
String[] countries=new
String[]{
"Afghastan","Albanie","Tunisie","Ukrania","Tchekozlovakia"
};
/**
Called when the activity is first created. */
@Override
public
void
onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
final
ArrayAdapter<String> adapter=new
ArrayAdapter<String>(this,
android.R.layout.simple_list_item_1,countries);
setListAdapter(adapter);
}
}
II/ ListView &
TextWatcher :=>Filtrer un listView :
a)Activity :
public
class
MainActivity extends
ListActivity {
private
EditText txtInput;
static
final
String[] countries
= new
String[] { "Afghastan",
"Albanie",
"Tunisie",
"Ukrania",
"Tchekozlovakia"
};
/**
Called when the activity is first created. */
@Override
public
void
onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
setContentView(R.layout.main);
final
ArrayAdapter<String> adapter = new
ArrayAdapter<String>(this,
android.R.layout.simple_list_item_1,
countries);
setListAdapter(adapter);
txtInput
= (EditText) findViewById(R.id.editText1);
txtInput.addTextChangedListener(new
TextWatcher() {
public
void
afterTextChanged(Editable theWatchedText) {
}
public
void
beforeTextChanged(CharSequence arg0, int
arg1,
int
arg2, int
arg3) {
//
Toast.makeText(getApplicationContext(), "BTC " + arg0,
//
1).show();
}
public
void
onTextChanged(CharSequence arg0, int
start, int
count,
int
after) {
adapter.getFilter().filter(arg0.toString());
//
Toast.makeText(getApplicationContext(), "OTC " + arg0,
//
1).show();
}
});
// addTextChangedListener
ListView
lv = getListView();
lv.setOnItemClickListener(new
OnItemClickListener() {
public
void
onItemClick(AdapterView<?> parent, View view,
int
position, long
id) {
Toast.makeText(getApplicationContext(),
((TextView)
view).getText(), Toast.LENGTH_SHORT).show();
}
});
/* AutoCompleteTextView
textView=(AutoCompleteTextView)findViewById(R.id.autocomplete_country);
ArrayAdapter<String>
adapter=new ArrayAdapter<String>(this, R.layout.list_item,
countries);
textView.setAdapter(adapter);*/
}
}
b)Xml Layout :
b.1=>list_item.xml :
<?xml
version="1.0"
encoding="utf-8"?>
<TextView
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:padding="10dp"
android:textColor="#000"
android:textSize="16sp"
>
</TextView>
b.2=>main.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="vertical"
>
<EditText
android:id="@+id/editText1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:ems="10"
android:hint="@string/hint1"
>
<requestFocus
/>
</EditText>
<ListView
android:id="@+id/android:list"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
>
</ListView>
</LinearLayout>
d
III/AutoComplete :
1)Activity :
public
class
MainActivity extends
Activity {
static
final
String[] countries
= new
String[] { "Afghastan",
"Albanie",
"Tunisie",
"Ukrania",
"Tchekozlovakia"
};
/**
Called when the activity is first created. */
@Override
public
void
onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
AutoCompleteTextView
textView=(AutoCompleteTextView)findViewById(R.id.autocomplete_country);
ArrayAdapter<String>
adapter=new
ArrayAdapter<String>(this,
R.layout.list_item,
countries);
textView.setAdapter(adapter);
}
}
2)LAyout :
=>list_item.xml
=>Meme que l'app précédente .
=>main.xml :
<?xml
version="1.0"
encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
>
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="country"
/>
<AutoCompleteTextView
android:id="@+id/autocomplete_country"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="5dp"
/>
</LinearLayout>
Excellent blog. I received a lot of info from this article and I will suggest to my friends to visit your blog. Keep continues...
ReplyDeleteSoft Skills Training in Chennai
best soft skills training in chennai
Appium Training in Chennai
Appium Certification in Chennai
JMeter Training in Chennai
Job Openings in Chennai
Pega Training in Chennai
Power BI Training in Chennai
Linux Training in Chennai
Tableau Training in Chennai
Spark Training in Chennai
Nice work with good ideas and concepts, lots of great information which we all need, helpful information. I would like to thank you for the efforts you shown remarkable writing skill in this article share some more info
ReplyDeleteAi & Artificial Intelligence Course in Chennai
PHP Training in Chennai
Ethical Hacking Course in Chennai Blue Prism Training in Chennai
UiPath Training in Chennai
Thank you for sharing this awesome blog with us. It is just fantastic blog with an awesome information.
ReplyDeleteAngularJS training in chennai | AngularJS training in anna nagar | AngularJS training in omr | AngularJS training in porur | AngularJS training in tambaram | AngularJS training in velachery