I tried all possible cases but data is not showing in the list from database.my starting activity have list view which is to be empty in starting and when user fill the data and save it from another activity,ans press back button the data should be shown in the first activity which have list view.,but every time data is not show

MainActivty.java

```
package com.example.smscampaign;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.database.Cursor;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.AdapterView;
import android.widget.ArrayAdapter;
import android.widget.Button;
import android.widget.ListView;
import android.widget.TextView;

public class Campaign_Details extends Activity  {

    private Demo selectedAdapter;
    private ArrayList<String> list;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_list_demostration);
        TextView text1=(TextView) findViewById(R.id.text1);
        TextView text2=(TextView) findViewById(R.id.text1);
        DataBaseHandler info= new DataBaseHandler(this);
        info.open();
        String data=info.getData();
        info.close();
        String[] values= new String[]{ data };  
        //txt.setText(data);
       // Button next=(Button) findViewById(R.id.next);
      //  Map<String, String[]> storage = new HashMap<String, String[]>();
     //   String[] tableItems = storage.get("ContactTable");

       // next.setOnClickListener(this);
    // final ListView listview = (ListView) findViewById(R.id.listview);

         ListView listview1 = (ListView) findViewById(R.id.listview1);
        // TextView emptyText = (TextView)findViewById(android.R.id.empty);

        //listview.setEmptyView(findViewById(R.id.empty));
    // TextView emptyText = (TextView)findViewById(android.R.id.empty);
        // listview .setEmptyView(emptyText);

        final ArrayList<String> list = new ArrayList<String>();
        for (int i = 0; i < values.length; ++i) {

            list.add(values[i]);
        }
        selectedAdapter = new Demo(this,values);
         ListView listview = (ListView) findViewById(R.id.listview);
        listview.setAdapter(selectedAdapter);

        listview.setOnItemClickListener(new AdapterView.OnItemClickListener() {

          @Override
          public void onItemClick(AdapterView<?> parent, final View view,
              int position, long id) {
              Intent n = new Intent(getApplicationContext(), SmsSend.class);
            startActivity(n);

          }
        });
    }

    @Override
    public boolean onCreateOptionsMenu(Menu menu) {

        // TODO Auto-generated method stub
        getMenuInflater().inflate(R.menu.main2, menu);
        return true;

    }

    @Override
    public boolean onOptionsItemSelected(MenuItem item) {
        // TODO Auto-generated method stub

        switch (item.getItemId()) {
        case R.id.nextPage:
            Intent i = new Intent(this,SmsSend.class);
            startActivity(i);
            break;

        }
        return super.onOptionsItemSelected(item);
    }
    } 

```

demo.java

```
package com.example.smscampaign;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

public class Demo extends ArrayAdapter{
    private Campaign_Details list1;
        // used to keep selected position in ListView
       private int selectedPos = -1;   // init value for not-selected
        private Context context;
        private String[] values;

        public Demo(Context context, String[] values) {
            super(context, R.layout.list);
            this.context = context;
            this.values = values;
        }

        public void setSelectedPosition(int pos){
        selectedPos = pos;
             // inform the view of this change
             notifyDataSetChanged();
        }
        public int getSelectedPosition(){
             return selectedPos;
        }
        @Override
        public View getView(int position, View convertView, ViewGroup parent) {
                 View v = convertView;
                        LayoutInflater vi =   (LayoutInflater)this.getContext().getSystemService(Context.LAYOUT_INFLATER_SERVICE);
                        v = vi.inflate(R.layout.list, null);

                 // get text view
                     TextView label = (TextView)v.findViewById(R.id.data);

                    if (convertView == null) {            
                        v = vi.inflate(R.layout.list, parent, false);
                    }
                    else
                        v = convertView;
                    TextView text1 = (TextView) v.findViewById(R.id.data);
                 text1.setText(values[position]); 
                    return v;
                }
        } 

```

activity\_list\_demonstration.xml

```
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical" >

    <TableLayout
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:orientation="horizontal"
        android:stretchColumns="3" >

        <TableRow
            android:layout_width="wrap_content"
            android:layout_height="wrap_content" >

            <TextView
                android:id="@+id/textcolour"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_gravity="left"
                android:background="@drawable/green_circle" />

            <TextView
                android:id="@+id/text1"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_gravity="center"
                android:paddingLeft="10dp"
                android:text="Active Campaign"
                android:textAppearance="?android:attr/textAppearanceLarge"
                android:textColor="#4AE56B" />

            <TextView
                android:id="@+id/textnum1"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_gravity="center"
                android:layout_marginRight="130dp"
                android:background="@drawable/green_badge"
                android:gravity="center"
                android:text=" 0 "
                android:textColor="@color/white" />
        </TableRow>
    </TableLayout>

    <LinearLayout
        android:layout_width="fill_parent"
        android:layout_height="240dp"
        android:orientation="vertical" >

        <ListView
            android:id="@+id/listview"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content" />
    </LinearLayout>

    <TableLayout
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:orientation="horizontal"
        android:stretchColumns="3" >

        <TableRow
            android:layout_width="wrap_content"
            android:layout_height="wrap_content" >

            <TextView
                android:id="@+id/textcolour"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_gravity="left"
                android:background="@drawable/grey_circle" />

            <TextView
                android:id="@+id/text2"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:paddingLeft="10dp"
                android:text="Closed Campaign"
                android:textAppearance="?android:attr/textAppearanceLarge" />

            <TextView
                android:id="@+id/textnum2"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_gravity="center"
                android:layout_marginRight="130dp"
                android:background="@drawable/grey_badge"
                android:gravity="center"
                android:text=" 0 "
                android:textColor="@color/white" />
        </TableRow>
    </TableLayout>

    <LinearLayout
        android:layout_width="fill_parent"
        android:layout_height="140dp"
        android:orientation="vertical" >

        <ListView
            android:id="@+id/listview1"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content" />
    </LinearLayout>

</LinearLayout>

```

list.xml

```
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:orientation="vertical" >

  <TextView
            android:id="@+id/data"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="text" >
        </TextView>

</LinearLayout>

```

DatabaseHandler.java// databaseclass

```
package com.example.smscampaign;

import android.content.ContentValues;
import android.content.Context;
import android.database.Cursor;
import android.database.SQLException;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteDatabase.CursorFactory;
import android.database.sqlite.SQLiteOpenHelper;

public class DataBaseHandler{

    public static final String KEY_ROWID="_id";
    public static final String KEY_NAME="person_name";
    public static final String KEY_SCALE="scale_person";

    private static final String DATABASE_NAME="Scaledb";
    private static final String DATABASE_TABLE="peopleTable";
    private static final int DATABASE_VERSION=1;

    private DbHelper ourHepler;
    private final Context ourContext;
    private SQLiteDatabase ourDatabase;
    public class DbHelper extends SQLiteOpenHelper{

        public DbHelper(Context context) {
            super(context,DATABASE_NAME,null,DATABASE_VERSION);
            // TODO Auto-generated constructor stub
        }

        @Override
        public void onCreate(SQLiteDatabase db) {
            // TODO Auto-generated method stub
            db.execSQL( "CREATE TABLE " + DATABASE_TABLE + " (" +
                    KEY_ROWID + " INTEGER PRIMARY KEY AUTOINCREMENT,  " +
                    KEY_NAME + " TEXT NOT NULL, " +
                    KEY_SCALE + " TEXT NOT NULL );"
                    );
            }

        @Override
        public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
            // TODO Auto-generated method stub
            db.execSQL("DROP TABLE IF EXISTS" + DATABASE_TABLE);
            onCreate(db);
        }

    }

    public DataBaseHandler(Context c){
        ourContext=c;
    }

    public DataBaseHandler open() throws SQLException{
        ourHepler = new DbHelper(ourContext);
        ourDatabase=  ourHepler.getWritableDatabase();
        return this;
    }
    public void close()
    {
        ourHepler.close();
    }

    public long entryCreate(String name, String scale) {
        // TODO Auto-generated method stub

        ContentValues cv=new ContentValues();
        cv.put(KEY_NAME, name);
        cv.put(KEY_SCALE, scale);
        return ourDatabase.insert(DATABASE_TABLE, null, cv); 

    }

    public String getData() {
        // TODO Auto-generated method stub
        String[] col= new String[]{KEY_ROWID,KEY_NAME,KEY_SCALE};
        Cursor c=  ourDatabase.query(DATABASE_TABLE, col, null, null, null, null, null);
        String run="";
        int iRow=c.getColumnIndex(KEY_ROWID);
        int iName=c.getColumnIndex(KEY_NAME);
        int iScale=c.getColumnIndex(KEY_SCALE);

        for(c.moveToFirst();!c.isAfterLast();c.moveToNext()){
            run=run+c.getString(iRow)+ " " + c.getString(iName) + " " + c.getString(iScale) + "\n";
        }

        return run;
    }

    public String getScale(long l) {
        // TODO Auto-generated method stub
        String[] col= new String[]{KEY_ROWID,KEY_NAME,KEY_SCALE};
        Cursor c= ourDatabase.query(DATABASE_TABLE, col,KEY_ROWID + "-" + l, null, null, null, null);

        if(c != null){
            c.moveToFirst();
            String scale=c.getString(2);
            return scale;
        }
        return null;
    }

    public String getName(long l)  {
        // TODO Auto-generated method stub
        String[] col= new String[]{KEY_ROWID,KEY_NAME,KEY_SCALE};
        Cursor c= ourDatabase.query(DATABASE_TABLE, col,KEY_ROWID + "-" + l, null, null, null, null);

        if(c != null){
            c.moveToFirst();
            String name=c.getString(1);
            return name;

        }
        return null;
    }

    public  void updateEntry(long lt, String mName, String mScale) {
        // TODO Auto-generated method stub
          ContentValues cvUpdate=new ContentValues();   
          cvUpdate.put(KEY_NAME,mName);
          cvUpdate.put(KEY_SCALE,mScale);
          ourDatabase.update(DATABASE_TABLE,  cvUpdate, KEY_ROWID + "-" + lt, null);
    }

    public void deleteEntry(long ltt) throws SQLException{
        // TODO Auto-generated method stub
        ourDatabase.delete(DATABASE_TABLE, KEY_ROWID + "=" + ltt,null);

    }
}

```