ListView သင္ေထာက္ကူ


===================

item မကူးတတ္ဘူးဆိုသူမ်ားအတြက္ နမူနာကုဒ္ခ်ေပးလိုက္ပါတယ္... သိပ္ၿပီး႐ွင္းျပစရာပါမယ္ေတာ့မထင္ပါဘူး... ပါလည္း မၾကာဘူး႐ွင္းျပမွာပါ... က်ေနာ္ ခုေတြးေနတာ ListView ေလးကုိၿပီးေအာင္သင္ရမလား... အျခားဟာဆက္ျပရမလားလို႔ပါ... စိတ္ထဲမွာ ListView ကုိသိပ္မေက်နပ္ခ်င္ဘူးဗ်... ခုေနေယာင္ဝါးဝါးလုပ္ခဲ့ရင္ GridView သင္တဲ့အခါပိုၿပီးေယာင္ဝါးဝါးျဖစ္ကုန္မွာလည္းစိုးရတယ္... cb ေလးခဏဖြင့္ပါတယ္... ေမးထားလိုက္ၾကတာဗ်ာ... မသိခ်င္ေယာင္ေဆာင္ၿပီးေျပးလာခဲ့ရတယ္... 😜 အဲဒီအထဲမွာ... android.R.layout.simple_list_item_1 ဆိုတာႀကီးပုံေသမသုံးခ်င္လို႔ ကြကုိယ္ layout လုပ္သုံးလို႔မရဘူးလားေမးထားတာေတြ႔ရတယ္... ေမးသင့္တဲ့ေမးခြန္းပါ... အေျဖက လုပ္လို႔ရပါတယ္... ေလာေလာဆယ္ အမ်ားႀကီးမေျပာခ်င္ေသးလို႔အလြယ္သင္ခဲ့တာပါ... မၾကာဘူးသင္ျပေပးပါမယ္...

main.xml
=========
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_height="match_parent"
android:layout_width="match_parent"
android:orientation="vertical">

<ListView
android:id="@+id/lv"
android:layout_height="wrap_content"
android:layout_width="match_parent"/>

</LinearLayout>

page_a.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"
android:gravity="center">

<TextView
android:layout_height="wrap_content"
android:text="This is Page A"
android:layout_width="wrap_content"/>

</LinearLayout>

MainActivity.java
===============
package com.ktr.mmlesson2;

import android.app.*;
import android.os.*;
import android.widget.*;
import android.widget.AdapterView.*;
import android.view.*;
import android.content.*;

public class MainActivity extends Activity
{
ListView lv;
String[] str ={"A","B","C","D","E"};
    @Override
    protected void onCreate(Bundle savedInstanceState)
    {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);

lv = (ListView)findViewById(R.id.lv);
ArrayAdapter<String> adapter = new ArrayAdapter<String>(this,
android.R.layout.simple_list_item_1, android.R.id.text1, str);
lv.setAdapter(adapter);

lv.setOnItemClickListener(new OnItemClickListener() {

public void onItemClick(AdapterView<?> parent, View view,
int position, long id) {
switch(position){
case 0:
Intent i = new Intent(MainActivity.this,PageA.class);
startActivity(i);
break;
}

}
});   

    }
}

PageA.java
==========
package com.ktr.mmlesson2;

import android.app.*;
import android.os.*;

public class PageA extends Activity
{

@Override
protected void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.page_a);
}

}

AndroidManifest.xml
==================
    </application> အထက္မွာကပ္ၿပီးထည့္ေပးပါ...

<activity
android:name=".PageA">
</activity>

Comments

Popular posts from this blog

Firebase (2)

Story Book Project (8)

Story Book Project (7)