nehasomany99 0 Newbie Poster

This is open.java file having java code.

package com.example.logo;




import android.app.Dialog;
import android.app.ListActivity;
import android.database.Cursor;
import android.os.Bundle;
import android.support.v4.widget.SimpleCursorAdapter;
import android.view.View;
import android.widget.AdapterView;
import android.widget.TextView;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.ListView;
import android.widget.Toast;

public class Open extends ListActivity {
    DbAdapter mDb = new DbAdapter(this);
    @Override
    protected void onDestroy() {
        // TODO Auto-generated method stub
        mDb.close();
        super.onDestroy();
    }


    /** Called when the activity is first created. */

    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.open);

        ListView listContent = (ListView) findViewById(android.R.id.list);

        mDb.open();
        Cursor cursor =mDb.fetchAllPrograms();
        startManagingCursor(cursor);

        String[] from = new String[] { DbAdapter.KEY_TITLE };
        int[] to = new int[] { R.id.textViewName };

        SimpleCursorAdapter cursorAdapter = new SimpleCursorAdapter(this, R.layout.row, cursor, from, to);
        listContent.setAdapter(cursorAdapter);


        //Onclick ListView setlistener
        listContent.setTextFilterEnabled(true);


            listContent.setOnItemClickListener(new OnItemClickListener() {
            public void onItemClick(AdapterView<?> parent, View view,int position, long id) {

            Toast.makeText(getApplicationContext(), "Working", Toast.LENGTH_LONG).show();

        }
    });


        }

    }

XML files are as follows:

Row.xml

<?xml version="1.0" encoding="utf-8"?>
<TextView
        android:id="@+id/textViewName"
        xmlns:android="http://schemas.android.com/apk/res/android"
        android:layout_marginTop="10dp"
         android:layout_marginBottom="10dp"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:textSize="25sp"
        android:textColor="#0000FF"
        android:textIsSelectable="true"
        android:focusable="false"
         />

open.xml:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="vertical"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    >
    <ListView
        android:id="@id/android:list"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:dividerHeight="0.1dp"
        android:divider="#0000CC"

        >
    </ListView>

</LinearLayout>

If I am going wrong, please correct me. Thanks in advance!

Be a part of the DaniWeb community

We're a friendly, industry-focused community of 1.20 million developers, IT pros, digital marketers, and technology enthusiasts learning and sharing knowledge.