-2

I want to click TextView inside listview item and open a new Layout

Below is my main class, adapter class, and Logcat

I have try 3 way to startActivity but it fail (I have comment it below in adapter class)

This is my main activity Screen1.class

//add padding top - bottom for listview
LayoutInflater inflater = (LayoutInflater) getSystemService(Context.LAYOUT_INFLATER_SERVICE);
LinearLayout header = (LinearLayout) inflater.inflate(R.layout.header, null);
lvSchedule.addFooterView(header, null, false);
lvSchedule.addHeaderView(header, null, false);
//setup listView Adapter
scheduleAdapter = new Schedule_lvAdapter(Screen1.this, R.layout.schedule_listview, scheduleLvItems);
//setup adapter to listView
lvSchedule.setAdapter(scheduleAdapter);
//setup OnClickListener
lvSchedule.setOnItemClickListener(new AdapterView.OnItemClickListener() {
    @Override
    public void onItemClick(AdapterView<?> adapterView, View view, int i, long l) {

        int postion = i - lvSchedule.getHeaderViewsCount();
        toggle(view, postion);

    }
});

This my listview adapter class

public class Schedule_lvAdapter extends ArrayAdapter<Schedule_lvItem> {

    List<Schedule_lvItem> scheduleLvItems;
    private Context context;

    public Schedule_lvAdapter(Context context, int textViewResourceId, List<Schedule_lvItem> objects) {
        super(context, textViewResourceId, objects);

        this.scheduleLvItems = objects;
        this.context = context;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        View v = convertView;
        viewHolder vh = null;

        if(v == null){

            vh = new viewHolder();
            LayoutInflater vi = (LayoutInflater)getContext().getSystemService(Context.LAYOUT_INFLATER_SERVICE);
            v = vi.inflate(R.layout.schedule_listview,null);
            v.setBackgroundResource(R.drawable.custom_middle_listview);

            vh.wrapper = (LinearLayout) v.findViewById(R.id.wrapper);
            vh.imgDay = (ImageView) v.findViewById(R.id.imgDay);
            vh.customView = (CustomView_Schedule) v.findViewById(R.id.view);
            vh.txtTime1 = (TextView) v.findViewById(R.id.txtTime1);
            vh.txtTime2 = (TextView) v.findViewById(R.id.txtTime2);
            vh.txtTime3 = (TextView) v.findViewById(R.id.txtTime3);
            vh.txtTime4 = (TextView) v.findViewById(R.id.txtTime4);
            vh.txtTime5 = (TextView) v.findViewById(R.id.txtTime5);
            vh.txtSubject1 = (TextView) v.findViewById(R.id.txtSubject1);
            vh.txtSubject2 = (TextView) v.findViewById(R.id.txtSubject2);
            vh.txtSubject3 = (TextView) v.findViewById(R.id.txtSubject3);
            vh.txtSubject4 = (TextView) v.findViewById(R.id.txtSubject4);
            vh.txtSubject5 = (TextView) v.findViewById(R.id.txtSubject5);

            vh.txtSubject1.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View view) {
                Toast.makeText(getContext(),"Clicked",1).show();
                    //first try
                    //view.getContext().startActivity(new Intent(view.getContext(), Schedule_Detail.class));
                    //second try
                    //context.startActivity(new Intent(context,Schedule_Detail.class));
                    //third try
                    //getContext().startActivity(new Intent(getContext(),Schedule_Detail.class));
                }
            });
            vh.txtSubject2.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View view) {
                    Toast.makeText(getContext(),"Clicked",1).show();
                }
            });
            vh.txtSubject3.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View view) {
                    Toast.makeText(getContext(),"Clicked",1).show();
                }
            });
            vh.txtSubject4.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View view) {
                    Toast.makeText(getContext(),"Clicked",1).show();
                }
            });
            vh.txtSubject5.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View view) {
                    Toast.makeText(getContext(),"Clicked",1).show();
                }
            });

            v.setTag(vh);

        }else{
            vh = (viewHolder)v.getTag();
        }
.....

Schedual detail class

package com.prototype.auinsight.schedual_listview;

import android.app.Activity;
import android.os.Bundle;

/**
 * Created by sattha on 5/30/2014.
 */
public class Schedule_Detail extends Activity {

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

    }
}

LOG CAT

05-30 20:27:13.974      496-496/com.prototype.auinsight.schedual_listview E/AndroidRuntime﹕ FATAL EXCEPTION: main
    android.content.ActivityNotFoundException: Unable to find explicit activity class {com.prototype.auinsight.schedual_listview/com.prototype.auinsight.schedual_listview.Schedule_Detail}; have you declared this activity in your AndroidManifest.xml?
            at android.app.Instrumentation.checkStartActivityResult(Instrumentation.java:1404)
            at android.app.Instrumentation.execStartActivity(Instrumentation.java:1378)
            at android.app.Activity.startActivityForResult(Activity.java:2817)
            at android.app.Activity.startActivity(Activity.java:2923)
            at com.prototype.auinsight.schedual_listview.Schedule_lvAdapter$1.onClick(Schedule_lvAdapter.java:60)
            at android.view.View.performClick(View.java:2408)
            at android.view.View$PerformClick.run(View.java:8816)
            at android.os.Handler.handleCallback(Handler.java:587)
            at android.os.Handler.dispatchMessage(Handler.java:92)
            at android.os.Looper.loop(Looper.java:123)
            at android.app.ActivityThread.main(ActivityThread.java:4627)
            at java.lang.reflect.Method.invokeNative(Native Method)
            at java.lang.reflect.Method.invoke(Method.java:521)
            at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:868)
            at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:626)
            at dalvik.system.NativeStart.main(Native Method)
Jongz Puangput
  • 5,527
  • 10
  • 58
  • 96
  • 3
    You haven't added `Schedule_Detail` in your manifest file – Apoorv May 30 '14 at 13:32
  • possible duplicate of [Unfortunately MyApp has stopped. How can I solve this?](http://stackoverflow.com/questions/23353173/unfortunately-myapp-has-stopped-how-can-i-solve-this) – njzk2 May 30 '14 at 13:34
  • 1
    See this LogCat line: `android.content.ActivityNotFoundException: Unable to find explicit activity class {com.prototype.auinsight.schedual_listview/com.prototype.auinsight.schedual_listview.Schedule_Detail}; have you declared this activity in your AndroidManifest.xml?` – Phantômaxx May 30 '14 at 13:39

3 Answers3

-1

Declare your activity Schedule_Detail.class in the manifest file. It may solve your problem.

suraj shukla
  • 258
  • 1
  • 3
  • 14
-1

write this in your manifest

<activity name=".Schedule_Detail">
 </activity>

and then give it a try.

Meenal
  • 2,879
  • 5
  • 19
  • 43
-1

its A simple solution... you haven't declared your activity in manifest file...

<activity name=".Schedule_Detail"> </activity>

write this in your manifest file and you got the solution..

Pragnesh Ghoda シ
  • 8,318
  • 3
  • 25
  • 40