Click here to Skip to main content
15,891,253 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
Hi frnds, This is my login page.when i sign in this page it is not redirect to listview page which contains datas.
here i want to redirect my page to categorylistactivity class.
This is my login page code:
Java
package com.example.uidesign;
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Toast;

public class signinactivity extends Activity {
	EditText edname,edpwd;
	Button b;
	LoginDataBaseAdapter logindatabaseadapter;
	protected void onCreate(Bundle savedInstanceState) 
	{
		super.onCreate(savedInstanceState);
		setContentView(R.layout.login);
		logindatabaseadapter=new LoginDataBaseAdapter(this);
		logindatabaseadapter=logindatabaseadapter.open();
		edname=(EditText) findViewById(R.id.editTextUserNameToLogin);
		edpwd=(EditText) findViewById(R.id.editTextPasswordToLogin);
		b=(Button) findViewById(R.id.buttonSignIn);
		b.setOnClickListener(new OnClickListener() {
			
			@Override
			public void onClick(View v) {
				String userName=edname.getText().toString();
				String password=edpwd.getText().toString();
				String storedpassword=logindatabaseadapter.getSinlgeEntry(userName);
				if(password.equals(storedpassword))
				{
					Toast.makeText(signinactivity.this, "Logged in Successfully", Toast.LENGTH_LONG).show();
					Intent i=new Intent(signinactivity.this,CategoryListActivity.class);
					startActivity(i);
				}
				else
				{
					Toast.makeText(signinactivity.this, "Password Does not match", Toast.LENGTH_LONG).show();
				}				
			}
		});
	}
}

This is my CategorylistActivity class:
Java
package com.example.uidesign;

import java.util.ArrayList;
import java.util.List;

import android.app.Activity;
import android.app.ListActivity;
import android.os.Bundle;
import android.widget.ArrayAdapter;
import android.widget.Button;
import android.widget.ListAdapter;
import android.widget.ListView;
import android.widget.SimpleCursorAdapter;

public class CategoryListActivity extends ListActivity {
	ListView lists;
	Button b;
	LoginDataBaseAdapter logindatabaseadapter;
	
	protected void oncreate(Bundle savedInstanceState)
	{
		super.onCreate(savedInstanceState);
		setContentView(R.layout.categorieslist);
		lists=(ListView) findViewById(R.id.lv);
		logindatabaseadapter=new LoginDataBaseAdapter(this);
		logindatabaseadapter=logindatabaseadapter.open();
		List<string> values=logindatabaseadapter.getname();
		ListAdapter adapter=new ArrayAdapter<string>(this, android.R.layout.simple_list_item_1,values);
		setListAdapter(adapter);	
	}
}


here is my logindatabaseadapter class:

In this All methods are ok except getname method, because this method only belongs to listview activity.all others are belongs to login related methods.
Java
package com.example.uidesign;

import java.util.ArrayList;
import java.util.List;

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

public class LoginDataBaseAdapter 
{
		static final String DATABASE_NAME = "login.db";
		static final int DATABASE_VERSION = 1;
		public static final int NAME_COLUMN = 1;
		// TODO: Create public field for each column in your table.
		// SQL Statement to create a new database.
		static final String DATABASE_CREATE = "create table "+"LOGIN"+
		                             "( " +"ID"+" integer primary key autoincrement,"+ "USERNAME  text,PASSWORD text); ";
		static final String DATABASE_CREATE1="create table category( "+ " ID integer primary key autoincrement, " + "NAME text);";
		// Variable to hold the database instance
		public  SQLiteDatabase db;
		// Context of the application using the database.
		private final Context context;
		// Database open/upgrade helper
		private DataBaseHelper dbHelper;
		public  LoginDataBaseAdapter(Context _context) 
		{
			context = _context;
			dbHelper = new DataBaseHelper(context, DATABASE_NAME, null, DATABASE_VERSION);
		}
		public  LoginDataBaseAdapter open() throws SQLException 
		{
			db = dbHelper.getWritableDatabase();
			return this;
		}
		public void close() 
		{
			db.close();
		}

		public  SQLiteDatabase getDatabaseInstance()
		{
			return db;
		}
		public List<string> getname()
		{
			String query="SELECT *FROM" + DATABASE_CREATE1;
			Cursor c=db.rawQuery(query,null);
			List<string> li=new ArrayList<string>();
			int irow=c.getColumnIndex("ID");
			int iname=c.getColumnIndex("NAME");
			for(c.moveToFirst();!c.isAfterLast();c.moveToNext()){
				li.add(c.getString(irow)+"  "+c.getString(iname));
			}
			return li;
		}

		public void insertEntry(String userName,String password)
		{
	       ContentValues newValues = new ContentValues();
			// Assign values for each row.
			newValues.put("USERNAME", userName);
			newValues.put("PASSWORD",password);
			
			// Insert the row into your table
			db.insert("LOGIN", null, newValues);
			///Toast.makeText(context, "Reminder Is Successfully Saved", Toast.LENGTH_LONG).show();
		}
		public int deleteEntry(String UserName)
		{
			//String id=String.valueOf(ID);
		    String where="USERNAME=?";
		    int numberOFEntriesDeleted= db.delete("LOGIN", where, new String[]{UserName}) ;
	       // Toast.makeText(context, "Number fo Entry Deleted Successfully : "+numberOFEntriesDeleted, Toast.LENGTH_LONG).show();
	        return numberOFEntriesDeleted;
		}	
		public String getSinlgeEntry(String userName)
		{
			Cursor cursor=db.query("LOGIN", null, " USERNAME=?", new String[]{userName}, null, null, null);
	        if(cursor.getCount()<1) // UserName Not Exist
	        {
	        	cursor.close();
	        	return "NOT EXIST";
	        }
		    cursor.moveToFirst();
			String password= cursor.getString(cursor.getColumnIndex("PASSWORD"));
			cursor.close();
			return password;				
		}
		public void  updateEntry(String userName,String password)
		{
			// Define the updated row content.
			ContentValues updatedValues = new ContentValues();
			// Assign values for each row.
			updatedValues.put("USERNAME", userName);
			updatedValues.put("PASSWORD",password);
			
	        String where="USERNAME = ?";
		    db.update("LOGIN",updatedValues, where, new String[]{userName});			   
		}
}

Here is my DataHelper class:
Java
package com.example.uidesign;

import android.content.ContentValues;
import android.content.Context;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteDatabase.CursorFactory;
import android.database.sqlite.SQLiteOpenHelper;
import android.util.Log;

public class DataBaseHelper extends SQLiteOpenHelper
{
	public DataBaseHelper(Context context, String name,CursorFactory factory, int version) 
    {
	           super(context, name, factory, version);
	}
	// Called when no database exists in disk and the helper class needs
	// to create a new one.
	@Override
	public void onCreate(SQLiteDatabase _db) 
	{
			_db.execSQL(LoginDataBaseAdapter.DATABASE_CREATE);
			_db.execSQL(LoginDataBaseAdapter.DATABASE_CREATE1);
			
			ContentValues cv=new ContentValues();
			cv.put("NAME", "TAXI");
			_db.insert("category", null, cv);
			
			cv.put("NAME", "FOOD ORDERING");
			_db.insert("category", null, cv);
			
			cv.put("NAME", "HOSPITAL");
			_db.insert("category", null, cv);
			
			cv.put("NAME", "TICKET BOOKING");
			_db.insert("category", null, cv);
			
			cv.put("NAME", "POLICE");
			_db.insert("category", null, cv);
			
			cv.put("NAME", "EMERGENCY");
			_db.insert("category", null, cv);
			
	}
	// Called when there is a database version mismatch meaning that the version
	// of the database on disk needs to be upgraded to the current version.
	@Override
	public void onUpgrade(SQLiteDatabase _db, int _oldVersion, int _newVersion) 
	{
			// Log the version upgrade.
			Log.w("TaskDBAdapter", "Upgrading from version " +_oldVersion + " to " +_newVersion + ", which will destroy all old data");
	
	
			// Upgrade the existing database to conform to the new version. Multiple
			// previous versions can be handled by comparing _oldVersion and _newVersion
			// values.
			// The simplest case is to drop the old table and create a new one.
			_db.execSQL("DROP TABLE IF EXISTS " + "TEMPLATE");
			_db.execSQL("DROP TABLE IF EXISTS " + "TEMPLATE");
			// Create a new one.
			onCreate(_db);
	}
}


please help me to solve this issue.Thanks in Advance
Posted
Updated 12-Aug-13 3:53am
v3
Comments
ridoy 12-Aug-13 9:06am    
i am in doubt whether anyone is going to help you for this huge code!
walterhevedeich 13-Aug-13 3:56am    
Have you checked LogCat? If the activity is not loading, perhaps there is an error there. Or maybe the activity is not associated to any layout. Have you checked your Android Manifest file?
prabu19 13-Aug-13 6:53am    
yes.everything ok. Now i need is, when sign in by username and password then it will go a basic listview which has array values.how can i solve this..
walterhevedeich 13-Aug-13 8:59am    
If this is a different issue, then perhaps you need to post a different question and describe the issue there in detail. Good for you that you have figured this out on your own.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900