Skip to main content

ANDROID - Using Fragments

I have used android-support-v4.jar because i have to run this in my Android 2.2.1 Device






Main Activity:

 package com.example.freagmenttest;  
 import android.os.Bundle;  
 import android.support.v4.app.FragmentActivity;  
 import android.view.Menu;  
 public class MainActivity extends FragmentActivity {  
      @Override  
      public void onCreate(Bundle savedInstanceState) {  
           super.onCreate(savedInstanceState);  
           setContentView(R.layout.activity_main);  
      }  
      @Override  
      public boolean onCreateOptionsMenu(Menu menu) {  
           getMenuInflater().inflate(R.menu.activity_main, menu);  
           return true;  
      }  
 }  

activity_main.xml

 <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"  
   android:orientation="horizontal"  
   android:layout_width="fill_parent"  
   android:layout_height="fill_parent">  
   <fragment android:name="com.example.freagmenttest.ItemClass"  
        android:id="@+id/headlines_fragment"  
        android:layout_weight="1"  
        android:layout_width="0dp"  
        android:layout_height="match_parent" />  
   <fragment android:name="com.example.freagmenttest.DetailsClass"  
        android:id="@+id/article_fragment"  
        android:layout_weight="2"  
        android:layout_width="0dp"  
        android:layout_height="match_parent" />  
 </LinearLayout>  

ItemClass:

 package com.example.freagmenttest;  
 import java.util.ArrayList;  
 import android.os.Bundle;  
 import android.support.v4.app.ListFragment;  
 import android.view.View;  
 import android.widget.ArrayAdapter;  
 import android.widget.ListView;  
 public class ItemClass extends ListFragment {  
      ArrayList<String> items = new ArrayList<String>();  
      DetailsClass frag;  
      int position = 0;  
      @Override  
      public void onCreate(Bundle savedInstanceState) {  
           // TODO Auto-generated method stub  
           super.onCreate(savedInstanceState);  
           fillarray();  
           setListAdapter(new ArrayAdapter<String>(getActivity(),  
                     android.R.layout.simple_list_item_1, items));  
      }  
      @Override  
      public void onActivityCreated(Bundle savedInstanceState) {  
           // TODO Auto-generated method stub  
           getListView().requestFocusFromTouch();  
           getListView().setSelection(position);  
           getListView().performItemClick(  
                     getListView().getAdapter().getView(position, null, null),  
                     position, position);  
           super.onActivityCreated(savedInstanceState);  
      }  
      @Override  
      public void onListItemClick(ListView l, View v, int position, long id) {  
           // TODO Auto-generated method stub  
           frag = (DetailsClass) getFragmentManager().findFragmentById(  
                     R.id.article_fragment);  
           if (frag != null && frag.isInLayout()) {  
                frag.setText(items.get(position), position);  
           }  
           super.onListItemClick(l, v, position, id);  
      }  
      private void fillarray() {  
           // TODO Auto-generated method stub  
           items.clear();  
           items.add("Android alpha");  
           items.add("Android beta");  
           items.add("1.5 Cupcake (API level 3)");  
           items.add("1.6 Donut (API level 4)");  
           items.add("2.0 Eclair (API level 5)");  
           items.add("2.0.1 Eclair (API level 6)");  
           items.add("2.1 Eclair (API level 7)");  
           items.add("2.2–2.2.3 Froyo (API level 8)");  
           items.add("2.3–2.3.2 Gingerbread (API level 9)");  
           items.add("2.3.3–2.3.7 Gingerbread (API level 10)");  
           items.add("3.0 Honeycomb (API level 11)");  
           items.add("3.1 Honeycomb (API level 12)");  
           items.add("3.2 Honeycomb (API level 13)");  
           items.add("4.0–4.0.2 Ice Cream Sandwich (API level 14)");  
           items.add("4.0.3–4.0.4 Ice Cream Sandwich (API level 15)");  
           items.add("4.1 Jelly Bean (API level 16)");  
           items.add("4.2 Jelly Bean (API level 17)");  
           items.add("5.0 Key Lime Pie (API level 18)");  
      }  
      public interface OnTutSelectedListener {  
           public void onTutSelected(String str);  
      }  
 }  

DetailsClass:

 package com.example.freagmenttest;  
 import android.os.Bundle;  
 import android.support.v4.app.Fragment;  
 import android.view.LayoutInflater;  
 import android.view.View;  
 import android.view.ViewGroup;  
 import android.widget.ImageView;  
 import android.widget.TextView;  
 public class DetailsClass extends Fragment {  
      @Override  
      public View onCreateView(LayoutInflater inflater, ViewGroup container,  
                Bundle savedInstanceState) {  
           View view = inflater.inflate(R.layout.detail, container, false);  
           return view;  
      }  
      public void setText(String item, int pos) {  
           TextView view = (TextView) getView().findViewById(R.id.textView1);  
           view.setText(item);  
           ImageView image = (ImageView) getView().findViewById(R.id.imageView1);  
           switch (pos) {  
           case 0:  
                image.setImageResource(R.drawable.android_alpha);  
                break;  
           case 1:  
                image.setImageResource(R.drawable.android_beta);  
                break;  
           case 2:  
                image.setImageResource(R.drawable.cupcake);  
                break;  
           case 3:  
                image.setImageResource(R.drawable.android_donut);  
                break;  
           case 4 & 5 & 6:  
                image.setImageResource(R.drawable.android_eclair);  
                break;  
           case 5:  
                image.setImageResource(R.drawable.android_eclair);  
                break;  
           case 6:  
                image.setImageResource(R.drawable.android_eclair);  
                break;  
           case 7:  
                image.setImageResource(R.drawable.android_froyo);  
                break;  
           case 8:  
                image.setImageResource(R.drawable.android_gingerbread);  
                break;  
           case 9:  
                image.setImageResource(R.drawable.android_gingerbread);  
                break;  
           case 10:  
                image.setImageResource(R.drawable.android_honeycomb);  
                break;  
           case 11:  
                image.setImageResource(R.drawable.android_honeycomb);  
                break;  
           case 12:  
                image.setImageResource(R.drawable.android_honeycomb);  
                break;  
           case 13:  
                image.setImageResource(R.drawable.android_ice_cream_sandwich);  
                break;  
           case 14:  
                image.setImageResource(R.drawable.android_ice_cream_sandwich);  
                break;  
           case 15:  
                image.setImageResource(R.drawable.jb_new_logo);  
                break;  
           case 16:  
                image.setImageResource(R.drawable.jb_new_logo);  
                break;  
           case 17:  
                image.setImageResource(R.drawable.android_kai);  
                break;  
           default:  
                break;  
           }  
      }  
 }  

detail.xml:

 <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"  
   android:layout_width="fill_parent"  
   android:layout_height="fill_parent"  
   android:orientation="vertical" >  
   <TextView  
     android:id="@+id/textView1"  
     android:layout_width="match_parent"  
     android:layout_height="wrap_content"  
     android:text="Large Text"  
     android:textAppearance="?android:attr/textAppearanceLarge" />  
   <ImageView  
     android:id="@+id/imageView1"  
     android:layout_width="match_parent"  
     android:layout_height="match_parent"  
     android:src="@drawable/ic_launcher" />  
 </LinearLayout>  

Manifst File:

 <manifest xmlns:android="http://schemas.android.com/apk/res/android"  
   package="com.example.freagmenttest"  
   android:versionCode="1"  
   android:versionName="1.0" >  
   <uses-sdk  
     android:minSdkVersion="8"  
     android:targetSdkVersion="15" />  
   <application  
     android:icon="@drawable/ic_launcher"  
     android:label="@string/app_name"  
     android:theme="@style/AppTheme" >  
     <activity  
       android:name=".MainActivity"  
       android:label="@string/title_activity_main" >  
       <intent-filter>  
         <action android:name="android.intent.action.MAIN" />  
         <category android:name="android.intent.category.LAUNCHER" />  
       </intent-filter>  
     </activity>  
   </application>  
 </manifest>  

Comments

Popular posts from this blog

Don't Ship AI Agent Skills Without Evals

At the AI Engineer World's Fair on July 1, 2026, Philipp Schmid, a Staff Engineer on the Gemini API and agents team at Google DeepMind, asked a room full of engineers a simple question: who uses skills with their coding agents? Every hand went up. Who has evals for those skills? Almost none. That gap is the entire talk, which Schmid also wrote up on his own blog, philschmid.de/testing-skills . His team indexed the skills ecosystem through SkillsBench and found the same pattern everywhere: people ship a SKILL.md file after two manual test runs and move on. It looks fine in a demo. It quietly corrupts outputs in production, because bad skills don't crash. They just make the agent confidently wrong. If you've already read our breakdown of Matt Pocock's Claude Code skills library , think of this as the other half of that story: what happens once you've installed a skill and it's actually running against real prompts. Key Takeaways SkillsBench indexed 47,000+ un...

Why Domain-Specific AI Agents Beat One Big Agent

Everyone is building agents right now. Real estate firms. Independent insurance brokers. Fortune 500 companies with budgets big enough to hire an army of consultants. Ask around and you'll hear the same story everywhere: "we're building our own agent." And yet almost nobody is asking the obvious question: why does the default approach keep failing? One large, general-purpose agent gets wired up to every tool the business owns. It impresses in the demo. Then it quietly stalls before production. There's a gap between what businesses want and what they're actually getting. They want AI woven into their data, their workflows, their day-to-day operations. What they get instead is one oversized agent trying to be a sales rep, a compliance officer, and a customer support line, all at once. That gap is an architecture problem, not a model problem. Key Takeaways The default "one big agent" pattern breaks down on context bloat, cost, fragility, and portability...

How Create AVD for Samsung Galaxy Tab

1. Open the Android AVD and SDK Manager  2.  Select Available Packages in the left panel of AVD Manager. 3.  Click “Add ADD-on Site” and enter the URL below. http://innovator.samsungmobile.com/android/repository/srepository.xml   4. Check Samsung GALAXY Tab Add-on packages and click install button. 5. Check Samsung GALAXY Tab Add-on license & Click install button. 6) After downloading and installation of GALAXY Tab Add-on, you should restart ADB (Android Debug Bridge) or Eclipse. The important specs of this device, from an Emulator perspective, are: Target platform: Android 2.2, Galaxy Tab Screen Info: High Density, despite the fact that it’s not, this is what it reports, WSVGA (1024×600) No keyboard Has dual cameras Let’s create an AVD configuration called GalaxyTab: Within Eclipse, launch the Android SDK and AVD Manager Select “Virtual Devices” from the left-hand options Click the “New” button to create a new AVD configura...