activity_main.xml
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" android:id="@+id/LinearLayout1" android:layout_width="match_parent" android:layout_height="match_parent" android:orientation="vertical" > <fragment android:id="@+id/fragment1" android:name="in.blogspot.kantapp.monthlistinfragmentandroidexample.MonthsListFragment" android:layout_width="match_parent" android:layout_height="match_parent" /> </LinearLayout>
MainActivity.java
package in.blogspot.kantapp.monthlistinfragmentandroidexample; import android.app.Activity; import android.os.Bundle; public class MainActivity extends Activity { @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); } }
MonthListFragment.java
package in.blogspot.kantapp.monthlistinfragmentandroidexample; /** * Created by kanta on 02-Jun-16. */ import android.annotation.SuppressLint; import android.app.ListFragment; import android.os.Bundle; import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; import android.widget.ArrayAdapter; @SuppressLint("NewApi") public class MonthsListFragment extends ListFragment { String[] MONTHS = { "jan", "feb", "march", "april", "may", "june", "july", "august", "sep", "octo", "nov", "dec" }; @Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { // TODO Auto-generated method stub ArrayAdapter<String> adapter = new ArrayAdapter<String>( inflater.getContext(), android.R.layout.simple_list_item_1, MONTHS); setListAdapter(adapter); return super.onCreateView(inflater, container, savedInstanceState); } }
No comments:
Post a Comment