Skip to main content

Posts

java sample code

package in.mangoishapps.myapplication; import android.content.Context; import android.support.v7.widget.CardView; import android.support.v7.widget.RecyclerView; import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; import android.widget.ImageView; import android.widget.TextView; import android.widget.Toast; import java.util.ArrayList; /** * Created by Avinash on 02-05-2015. */ public class RVAdapter extends RecyclerView.Adapter { LayoutInflater inflater; Context context; ArrayList chizes=new ArrayList (); RVAdapter(Context context) { this.context=context; inflater=LayoutInflater.from(context); } public void setData(ArrayList chizes) { this.chizes=chizes; } @Override public ViewHolder onCreateViewHolder(ViewGroup viewGroup, int i) { View view=inflater.inflate(R.layout.singlerow_linear,viewGroup,false); ViewHolder holder=new ViewHolder(view); return hold...

Navigation drawer, material design theme

Aim: To make an android app with navigation drawer, material design theme Feat: Toolbar is used instead of the ActionBar, When the user runs the app for the time , he/she can see the drawer opened on the launch of the app, also rotation doesn't effect the drawer (whose layout is a fragment). Used: Fragments in both Code:   MainActivity.java ______________________________________________________________________________________________________ DrawerList.Java______________________________________________________________________________________________ package cts.fastester; import android.content.Context; import android.content.SharedPreferences; import android.os.Bundle; import android.support.v4.app.Fragment; import android.support.v4.widget.DrawerLayout; import android.support.v7.app.ActionBarDrawerToggle; import android.support.v7.widget.Toolbar; import android.view.LayoutInflater; import android.view.View; import android.view.ViewGr...

Database create, read, update, delete in android

To create a db , first create a schema create a class that extends SQLiteOpenHelper create an object of SQLdatabse and initialise using getwritabledatabase create sepatrate methods for CRUD operation Schema class package com.example.avinash.sql2; import android.content.ContentValues; import android.content.Context; import android.database.Cursor; import android.database.sqlite.SQLiteDatabase; import android.database.sqlite.SQLiteOpenHelper; import java.sql.SQLException; /** * Created by Avinash on 01-01-2015. */ public class DBAdapter {     DBHelper helper;     public DBAdapter(Context c) {         helper = new DBHelper(c);     }     public long insertdata(String u,String p)     {   SQLiteDatabase sqldb=helper.getWritableDatabase();         ContentValues cv=new ContentValues();         c...

use view pager and sliding tabs

make fragments and corressponding layout make viewpager adapter import android.support.v4.app.Fragment; import android.support.v4.app.FragmentManager; import android.support.v4.app.FragmentPagerAdapter; public class MyPagerAdapter extends FragmentPagerAdapter {     public MyPagerAdapter(FragmentManager fm) {         super(fm);     }     @Override     public Fragment getItem(int position) {         Fragment f = null;         if (position == 0) {             f = new FragmentA();         }         if (position == 1) {             f = new FragmentB();         }         if (posi...

Use toolbar in android

Set the theme as Theme.AppCompat.Light.NoActionBar (it will make toggle and title color as black, to keep them white use Theme.AppCompat.NoActionBar) Make a separate app_bar.xml with the code <?xml version="1.0" encoding="utf-8"?> <android.support.v7.widget.Toolbar     xmlns:android=" http://schemas.android.com/apk/res/android"     android:layout_width="match_parent"     android:layout_height="wrap_content"> </android.support.v7.widget.Toolbar> include this layout at the top in your main activity layout using this code <include        android:id="@+id/app_bar"        layout="@layout/app_bar">    </include> add reference of this toolbar in mainactivity java file Toolbar tb=(Toolbar)findViewById(R.id.app_bar); setSupportActionBar(tb); getSupportActionBar().setHomeButtonEnabled(true);   //to make enable back buttton and ...