how to make list view in android studio - Geekyrishi

Post Top Ad

how to make list view in android studio

how to make list view in android studio

Share This












 

how to make list view in android studio

  Let's make list view in android studio

 
















android app code for list.java, 

 package com.blogspot.geekyrishi.hackingguider;


import android.content.Context;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v4.app.Fragment;
import android.support.v4.app.ListFragment;
import android.view.View;
import android.widget.ArrayAdapter;
import android.widget.ListView;


/**
 * A simple {@link Fragment} subclass.
 */
public class list extends ListFragment {

     //private PieceListener pieceListener;

    public list() {
        // Required empty public constructor
    }

    /*
    @Override
    public void onActivityCreated(@Nullable Bundle savedInstanceState) {
        super.onActivityCreated(savedInstanceState);

        setListAdapter(new ArrayAdapter<String>(this.getActivity(),android.R.layout.simple_list_item_1,getResources().getStringArray(R.array.pieces)));

         //pieceListener.onPieceSelected(0);
    }

    public interface PieceListener
    {
        public  void onPieceSelected(int index);
    }

    @Override
    public void onAttach(Context context) {
        super.onAttach(context);

        try{
          pieceListener=(PieceListener) context;
        }
        catch (ClassCastException e)
        {
          throw new ClassCastException(context.toString() + "interface called"+"PieceListner" );
        }
    }

    @Override
    public void onListItemClick(ListView l, View v, int position, long id) {
        pieceListener.onPieceSelected(position) ;
    }*/
}


android code for MainActivity.java

package com.blogspot.geekyrishi.hackingguider;

import android.support.v4.app.ListFragment;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.widget.TextView;

public class MainActivity extends AppCompatActivity /*implements list.PieceListener*/ {

   // TextView tvdetail;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
     //   tvdetail=(TextView) findViewById(R.id.tvdetail);
    }

  /*  @Override
    public void onPieceSelected(int index) {

        String[] desc = getResources().getStringArray(R.array.desc);
        tvdetail.setText(desc[index]);
    }*/
}



android code for Activity_Main.xml

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical"
    tools:context="com.blogspot.geekyrishi.hackingguider.MainActivity">


    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:orientation="horizontal">

        <fragment
            android:id="@+id/fragment"
            android:name="com.blogspot.geekyrishi.hackingguider.list"
            android:layout_width="wrap_content"
            android:layout_height="match_parent"
            android:layout_weight="2"
            tools:layout="@layout/fragment_list" />

        <fragment
            android:id="@+id/fragment2"
            android:name="com.blogspot.geekyrishi.hackingguider.detail"
            android:layout_width="wrap_content"
            android:layout_height="match_parent"
            android:layout_weight="5"
            tools:layout="@layout/fragment_detail" />

    </LinearLayout>






android code for Fragment_list.xml

 </LinearLayout>


<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"

    tools:context="com.blogspot.geekyrishi.hackingguider.detail">



</FrameLayout>


enjoy developing ;)

No comments:

Post a Comment

Post Bottom Ad