Hi Guys!
Today I am going to share the code the ListFragment. ListFragment class is available inside the the android support v4 library.
Fragment is a new concept which is introduced in Android 3.0 and its higher versions.
A fragment that displays a list of items by binding to a data source such as an array or Cursor, and exposes event handlers when the user selects an item.
ListFragment hosts a
For mode details, you can visit the android developer site for ListFragment.
Today I am going to share the code the ListFragment. ListFragment class is available inside the the android support v4 library.
Fragment is a new concept which is introduced in Android 3.0 and its higher versions.
A fragment that displays a list of items by binding to a data source such as an array or Cursor, and exposes event handlers when the user selects an item.
ListFragment hosts a
List View
object that can be bound to different data sources, typically either an array or a Cursor holding query results.For mode details, you can visit the android developer site for ListFragment.
activity_main.xml
FriendsList.java
package com.sunil.fragmentlistview;
import android.os.Bundle;
import android.support.v4.app.ListFragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.ArrayAdapter;
import android.widget.Toast;
public class FriendsList extends ListFragment implements OnItemClickListener{
String[] myFrriends = new String[] {
"Sunil Gupta",
"Abhishek Tripathi",
"Awadhesh Diwakar",
"Amit Verma",
"Jitendra Singh",
"Ravi Jhansi",
"Ashish Jain",
"Sandeep Pal",
"Shishir Verma",
"Ravi BBD"
};
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
ArrayAdapteradapter= new ArrayAdapter (inflater.getContext(), android.R.layout.simple_list_item_1, myFrriends);
setListAdapter(adapter);
return super.onCreateView(inflater, container, savedInstanceState);
}
// this code for item click of the list
@Override
public void onActivityCreated(Bundle savedInstanceState) {
super.onActivityCreated(savedInstanceState);
getListView().setOnItemClickListener(this);
}
@Override
public void onItemClick(AdapterView adapter, View view, int position, long id) {
Toast.makeText(getActivity().getBaseContext(), "Item clicked: " + myFrriends[position], Toast.LENGTH_LONG).show();
}
}
MainActivity.java
package com.sunil.fragmentlistview;
import com.sunil.fragmentlistview.R;
import android.os.Bundle;
import android.support.v4.app.FragmentActivity;
public class MainActivity extends FragmentActivity {
@Override
protected void onCreate(Bundle arg0) {
super.onCreate(arg0);
setContentView(R.layout.activity_main);
}
}
Update Contact :
No Wa/Telepon (puat) : 085267792168
No Wa/Telepon (fajar) : 085369237896
Email : Fajarudinsidik@gmail.com
No Wa/Telepon (puat) : 085267792168
No Wa/Telepon (fajar) : 085369237896
Email: Fajarudinsidik@gmail.com
atau Kirimkan Private messanger melalui email dengan klik tombol order dibawah ini :