ListView add item click item basic Android example code
Definition of ListView in layout main.xml file Android example
Code in Main.java ListView example source code Java Android
<ListView android:id="@+id/idListView"
android:background="#7700CC00"
android:layout_height="wrap_content"
android:layout_width="fill_parent" />
Code in Main.java ListView example source code Java Android
public class Main extends Activity {
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
ListView mlistView = (ListView) findViewById(R.id.idListView);
mlistView.setAdapter(new ArrayAdapter<String>(this,
android.R.layout.simple_list_item_1,
new String[] {"Game", "Help", "Home site"}));
mlistView.setOnItemClickListener(new OnItemClickListener() {
public void onItemClick(AdapterView<?> parent, View view,
int position, long id) {
// When clicked, show a toast with the TextView text Game, Help, Home
Toast.makeText(getApplicationContext(), ((TextView) view).getText(),
Toast.LENGTH_SHORT).show();
}
});
}
}
396LW NO topic_id
AD
Další témata ....(Topics)
Brand | Samsung |
Model (codename) | i9250 Galaxy Nexus |
Cena, včetně DPH | 9000 |
Veikost Displaye v palcích | 4.65 |
Display-resolution | 1280x720 |
Dotek-typ | kapacitní |
CPU typ | |
CPU MHz | 1200 |
CPU core | 2 |
L2 cache | |
RAM | 1 GB |
ROM | 16 - 32 GB |
GPU | TI OMAP 4460 1,2 GHz dual-core |
NenaMark2 Benchmark | |
GPU-GLBenchmark | |
Baterie mAh | 1750 |
Foto MPx | 5 |
Autofocus | yes |
Video | 480p - 30 frames/s |
Official Android ICS | Android 4.0 Ice Cream Sandwich |
CyanogenMod support | |
Dotek-prstů-max | |
Display-ppi | |
Display-retina | |
Network | GSM&EDGE: 850 / 900 / 1.800 / 1.900 |
Connectivity | |
Pozn. |
samsung-i9250-galaxy-nexus image
Close one project:¨
-right click on project
- select Close project
Close more projects:
- right click on project
- select Close Unrelated Projects
Hide closed projects:
- package explorer
- view menu
- select Closed projects
-right click on project
- select Close project
Close more projects:
- right click on project
- select Close Unrelated Projects
Hide closed projects:
- package explorer
- view menu
- select Closed projects
Kvalitní mobilní telefon pro rok 2012 by měl mít tyto, nebo ještě lepší parametry.
Značka Samsung , HTC, LG, Motorola, Sony Ericsson, ZTE Blade
Verze operačního systému Android 2.2 a vyšší.
Procesor a jeho frekvence Qualcomm 800MHz a vyšší.
Paměť RAM 512MB a více.
Paměť ROM 512MB.
Displej a jeho rozlišení 4,3 palce rozlišení 480x800 pixelů pro snadné ovládání a čtení a schopnost zobrazit 16 milionů barev.
Technologie 3G data, WiFi, BlueTooth, GPS přijímač, fotoaparát 3 Mpix, autofokus, diodový blesk.
Výdrž baterie minimálně 1 den a více.
3G internet.
Značka Samsung , HTC, LG, Motorola, Sony Ericsson, ZTE Blade
Verze operačního systému Android 2.2 a vyšší.
Procesor a jeho frekvence Qualcomm 800MHz a vyšší.
Paměť RAM 512MB a více.
Paměť ROM 512MB.
Displej a jeho rozlišení 4,3 palce rozlišení 480x800 pixelů pro snadné ovládání a čtení a schopnost zobrazit 16 milionů barev.
Technologie 3G data, WiFi, BlueTooth, GPS přijímač, fotoaparát 3 Mpix, autofokus, diodový blesk.
Výdrž baterie minimálně 1 den a více.
3G internet.
Call findViewById from onCreateView
res\layout
activity_main.xml
fragment_main.xml
public class MainActivity extends ActionBarActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
if (savedInstanceState == null) {
getSupportFragmentManager().beginTransaction()
.add(R.id.containerMoje, new PlaceholderFragment()).commit();
}
}
/**
* A placeholder fragment containing a simple view.
*/
public static class PlaceholderFragment extends Fragment {
public PlaceholderFragment() {
}
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
View rootView = inflater.inflate(R.layout.fragment_main, container,
false);
if (container == null) {
return null;
}
TextView mText;
mText = (TextView)rootView.findViewById(R.id.idText);
mText.setText("Hello from fragment_main");
return rootView;
}
}
}
res\layout
activity_main.xml
<FrameLayout xmlns:android="//schemas.android.com/apk/res/android"
xmlns:tools="//schemas.android.com/tools"
android:id="@+id/containerMoje"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context="cz.okhelp.autoskola.MainActivity"
tools:ignore="MergeRootFrame" />
fragment_main.xml
<RelativeLayout xmlns:android="//schemas.android.com/apk/res/android"
xmlns:tools="//schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
tools:context="cz.okhelp.autoskola.MainActivity$PlaceholderFragment" >
<TextView
android:id="@+id/idText"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/hello_world" />
</RelativeLayout>
Physical pixel (px)
Density independent pixel (dp)
Dots per inch (dpi) .. physical pixels per inch
px = dp * (dpi / 160)
Density independent pixel (dp)
Dots per inch (dpi) .. physical pixels per inch
px = dp * (dpi / 160)
public static int dpToPx(int dp)
{
return (int) (dp * Resources.getSystem().getDisplayMetrics().density);
}
public static int pxToDp(int px)
{
return (int) (px / Resources.getSystem().getDisplayMetrics().density);
}
Editace: 2011-09-16 11:48:11
Počet článků v kategorii: 396
Url:listview-add-item-click-item-basic-android-example-code