Friday, 5 January 2018

Horizontal gridview in android easy to put

 
 
 
 
<HorizontalScrollView 
android:layout_width="match_parent" 
android:layout_marginTop="650dp"android:layout_marginLeft="20dp" 
android:layout_marginRight="20dp" 
android:layout_height="fill_parent"
 android:id="@+id/horizontalScrollView">
 <FrameLayoutandroid:layout_width="1000dp" 
 android:layout_height="wrap_content">
 <LinearLayout
 android:id="@+id/linearLayout_gridtableLayout" 
android:layout_width="500dp" 
android:layout_marginLeft="0dp" 
android:layout_height="100dp"
 android:orientation="horizontal">
<GridViewandroid:id="@+id/gridView"
 android:layout_width="fill_parent"
 android:layout_height="fill_parent"android:layout_margin="4dp" 
android:columnWidth="60dp"android:gravity="center"android:numColumns="5" 
android:horizontalSpacing="1dp"android:scrollbarAlwaysDrawHorizontalTrack="true"
 android:scrollbarAlwaysDrawVerticalTrack="true"android:scrollbars="horizontal" 
android:stretchMode="none"android:verticalSpacing="1dp">
 </GridView> </LinearLayout> </FrameLayout>
</HorizontalScrollView>
 
 
 
 
 
 

Tuesday, 2 January 2018

Gridview with two texts in android

Gridview with two texts in android

Reply with comment




Manefest:

<?xml version="1.0" encoding="utf-8"?>
 <manifest xmlns:android="http://schemas.android.com/apk/res/android"    package="com.example.admin.grid1"> 
<application 
 android:allowBackup="true" 
 android:icon="@mipmap/ic_launcher" 
 android:label="@string/app_name" 
 android:supportsRtl="true" 
 android:theme="@style/AppTheme">
        <activity android:name=".MainActivity">
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />

                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
    </application>

</manifest>
 

activity_main:

<?xml version="1.0" encoding="utf-8"?> 
<RelativeLayout 
 xmlns:android="http://schemas.android.com/apk/res/android" 
 xmlns:tools="http://schemas.android.com/tools" 
 android:layout_width="match_parent" 
 android:layout_height="match_parent"> 
 <GridView xmlns:android="http://schemas.android.com/apk/res/android" 
 android:id="@+id/gridview" 
 android:layout_width="match_parent" 
 android:layout_height="wrap_content" 
 android:background="#cccccc" 
 android:horizontalSpacing="1dp" 
 android:numColumns="3" 
 android:stretchMode="columnWidth" 
 android:verticalSpacing="1dp" />
</RelativeLayout>
   

grid_layout:

<?xml version="1.0" encoding="utf-8"?> 
 <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
 android:layout_width="match_parent" 
 android:layout_height="match_parent" 
 android:orientation="vertical" 
 android:gravity="center" 
 android:background="#fff" 
 android:padding="15dp" 
 > 
<TextView 
 android:layout_width="wrap_content" 
 android:layout_height="wrap_content" 
 android:text="Medium Text" 
 android:id="@+id/textView" 
 android:layout_gravity="center_horizontal" /> 
<TextView 
 android:id="@+id/grid_item_label" 
 android:layout_marginTop="5dp" 
 android:layout_width="wrap_content" 
 android:layout_height="wrap_content" 
 android:text="Medium Text" 
 android:textColor="#555" /> 
</LinearLayout>

MainActivity: 


public class MainActivity extends AppCompatActivity {

    String[] web = {
            "one",
            "one",
            "one",
            "one",
            "one",
            "one",
            "one",
            "one",
            "one",
            "one"

    } ;
    String[] web2 = {
            "two",
            "two",
            "two",
            "two",
            "two",
            "two",
            "two",
            "two",
            "two",
            "two"

    } ;




    @Override 
 protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        Img1 adapter = new Img1(MainActivity.this,web,web2);

        GridView gridview = (GridView) findViewById(R.id.gridview);


        gridview.setAdapter(adapter);
        gridview.setOnItemClickListener(new AdapterView.OnItemClickListener() {
            public void onItemClick(AdapterView<?> parent, View v,
                                    int position, long id) {
                if(position==0)
                {
                    Toast.makeText(MainActivity.this, "add", Toast.LENGTH_SHORT).show();
                }
                if(position==1)
                {

                }
                if(position==2)
                {

                }
                if(position==3)
                {

                }
                if(position==4)
                {

                }
                if(position==5)
                {

                }
            }
        });
    }
}


Img1:


public class Img1 extends BaseAdapter
{
    private Context mContext;
    private final String[] web;
    private final String[] web2;
    public Img1(Context c, String[] web,String[] web2 )
    {
        mContext = c;
        this.web=web;
        this.web2=web2;
    }



    @Override    public int getCount()
    {

        return web.length;
    }
    @Override    public Object getItem(int position)
    {
        return position;
    }
    @Override    public long getItemId(int position)
    {
        return 0;
    }
    @Override    public View getView(int position, View convertView, ViewGroup
            parent)
    {
        LayoutInflater inflater = (LayoutInflater)
                mContext.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
        View gridView;
        if (convertView == null)
        {
            gridView = new View(mContext);
            // get layout from mobile.xml 
 gridView = inflater.inflate(R.layout.grid_layout, null);
            // set value into textview 
 TextView textView = (TextView)gridView.findViewById(R.id.grid_item_label);
 TextView textView2 = (TextView)gridView.findViewById(R.id.textView);

            textView.setText(web[position]);
            textView2.setText(web2[position]);
            // set image based on selected text

        }
        else 
 {
            gridView = (View) convertView;
        }
        return gridView;
    }
} 

Wednesday, 18 January 2017

Text in Listview in android using volley library

1.build.gradle(Module:app)

apply plugin: 'com.android.application'
android {
    compileSdkVersion 24 
 buildToolsVersion "24.0.2"
    defaultConfig {
 applicationId "com.bhanu.bhanu1.volleyimage" 
 minSdkVersion 15 
 targetSdkVersion 24 
 versionCode 1 
 versionName "1.0" 
 }
    buildTypes {
 release {
 minifyEnabled false 
 proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' 
 }
    }
}

dependencies {
    compile fileTree(dir: 'libs', include: ['*.jar'])
    testCompile 'junit:junit:4.12' 
 
    compile 'com.android.support:appcompat-v7:24.2.1' 
    compile 'com.android.volley:volley:1.0.0'
}


2.Manifest;

<?xml version="1.0" encoding="utf-8"?>
 <manifest xmlns:android="http://schemas.android.com/apk/res/android"    package="com.bhanu.bhanu1.volleyimage">

    <uses-permission android:name="android.permission.INTERNET" /> 
 
<application 
 android:allowBackup="true" 
 android:icon="@mipmap/ic_launcher" 
 android:label="@string/app_name" 
 android:supportsRtl="true" 
 android:theme="@style/AppTheme">
        <activity android:name=".MainActivity">
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />

                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
        
    </application>

</manifest>
3.Layout;

1.activity_main

<?xml version="1.0" encoding="utf-8"?>
  <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
 xmlns:tools="http://schemas.android.com/tools" 
 android:layout_width="match_parent"     
 android:layout_height="match_parent" 
 android:paddingBottom="@dimen/activity_vertical_margin" 
 android:paddingLeft="@dimen/activity_horizontal_margin" 
 android:paddingRight="@dimen/activity_horizontal_margin" 
 android:paddingTop="@dimen/activity_vertical_margin"    >

    <ListView 
 android:layout_width="wrap_content" 
 android:layout_height="wrap_content" 
 android:id="@+id/listView" 
 android:layout_alignParentTop="true" 
 android:layout_alignParentLeft="true" 
 android:layout_alignParentStart="true" />
 
 </RelativeLayout>

 
4.Activity:

public class MainActivity extends AppCompatActivity {
    ListView lv1;
    String url = "https://gist.githubusercontent.com/anonymous/5a052f20b1d2c5da8ffef29058f84bb8/raw/7a3296210445d8289a6b25302bc336702ed6b509/ead787b7-dd59-11e6-90ab-a17e7004c7c4.json";
    RequestQueue rq;
    String data = "";
    @Override    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        lv1 = (ListView)findViewById(R.id.listView);
        final ArrayAdapter<String> adapter = new ArrayAdapter<>(this,
                android.R.layout.simple_list_item_1, android.R.id.text1);
        rq = Volley.newRequestQueue(this);
        JsonArrayRequest jar1 = new JsonArrayRequest(url, new Response.Listener<JSONArray>()
        {
            @Override 
 public void onResponse(JSONArray response) {
                try {
                    JSONObject jo = response.getJSONObject(0);
                    JSONArray ja = jo.getJSONArray("colorArray");
                    for(int i = 0;i<ja.length();i++)
                    {
                        JSONObject jo1 = ja.getJSONObject(i);
                        String s1 = jo1.getString("name");
                        adapter.add(s1);
                    }
                    lv1.setAdapter(adapter);

                } catch (JSONException e) {
                    e.printStackTrace();
                }


            }
        }, new Response.ErrorListener() {
            @Override 
 public void onErrorResponse(VolleyError error) {
                Log.e("Volley","Error");
            }
        }
        );
        rq.add(jar1);

    }
}


Sunday, 1 January 2017

CustomToast

Java

1.MainActivity

public class MainActivity extends Activity {
@Override
   public void onCreate(Bundle savedInstanceState) {
       super.onCreate(savedInstanceState);
       setContentView(R.layout.activity_main);
     
       LayoutInflater li = getLayoutInflater();
       View layout = li.inflate(R.layout.customtoast,
         (ViewGroup) findViewById(R.id.custom_toast_layout));
   
       Toast toast = new Toast(getApplicationContext());
       toast.setDuration(Toast.LENGTH_SHORT);
       toast.setGravity(Gravity.CENTER_VERTICAL, 0, 0);
       toast.setView(layout);
       toast.show();
   }
   @Override
   public boolean onCreateOptionsMenu(Menu menu) {
       getMenuInflater().inflate(R.menu.activity_main, menu);
       return true;
   }

}

layouts

1.activity-main

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context=".MainActivity" >

    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_centerHorizontal="true"
        android:layout_centerVertical="true"
        android:text="@string/hello_world" />

</RelativeLayout>

2.customtoast

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
      android:id="@+id/custom_toast_layout"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical"
    android:background="#F14E23"
     >
     
    <ImageView
        android:id="@+id/custom_toast_image"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:contentDescription="@string/hello_world"
        android:src="@drawable/ic_launcher"/>
<TextView
        android:id="@+id/custom_toast_message"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:contentDescription="@string/Toast"
        android:text="@string/Toast" />
</LinearLayout>

Saturday, 31 December 2016

Simple notepad in android using sqlite database in simple manner

Java files

1.MainActivity

public class MainActivity extends AppCompatActivity {
    ListView lv;
    TextView tv3,tv5;
    SQLiteDatabase db;
    Cursor cursor;
    RelativeLayout rl;
    SharedPreferences sp;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.a);
        lv = (ListView)findViewById(R.id.listView);
        sp = getSharedPreferences("my_background",MODE_PRIVATE);
        rl = (RelativeLayout)findViewById(R.id.r2);
        int no = sp.getInt("k1",5475);
        if (no==101)
        {
            rl.setBackgroundColor(Color.WHITE);

        }
        else if (no==102)
        {
            rl.setBackgroundColor(Color.RED);

        }else if (no==103)
        {
            rl.setBackgroundColor(Color.GREEN);


        }
        db = openOrCreateDatabase("StudentRecordsDB", Context.MODE_PRIVATE, null);
        try {
            cursor = db.rawQuery("select * from news_inf", null);

            SimpleCursorAdapter adapter = new SimpleCursorAdapter(
                    MainActivity.this, R.layout.line, cursor
                    , new String[]{"_id", "news_title"}
                    , new int[]{R.id.id1, R.id.my_title});
            lv.setAdapter(adapter);
            lv.setOnItemClickListener(new AdapterView.OnItemClickListener() {
                @Override
                public void onItemClick(AdapterView<?> parent, View view,
                                        int position, long id) {
                    tv5 = (TextView) view.findViewById(R.id.id1);
                    tv3 = (TextView) view.findViewById(R.id.my_title);


                    String n1 = tv3.getText().toString();
                    String n3 = tv5.getText().toString();

                    Intent i = new Intent(getApplicationContext(), Delete.class);
                    i.putExtra("k1", n1);
                    i.putExtra("k3", n3);
                    startActivity(i);
                }
            });


        }

        catch (Exception e)
        {
            Log.e("Read Data", "" + e);
            Toast.makeText(MainActivity.this, "No Data", Toast.LENGTH_SHORT).show();
        }



    }
    public void one(View v)
    {
        Intent i = new Intent(this,Add.class);
        startActivity(i);
        overridePendingTransition(R.anim.abc_fade_in, R.anim.abc_fade_out);

    }
    public void six (View v)
    {
        tv5 = (TextView)v.findViewById(R.id.id1);

        String n1 = tv5.getText().toString();

        db.execSQL("DELETE FROM news_inf WHERE _id='" +n1+ "'");
        Toast.makeText(MainActivity.this, "deleted", Toast.LENGTH_SHORT).show();

        cursor.requery();
    }
    @Override
    public boolean onCreateOptionsMenu(Menu menu)
    {
        super.onCreateOptionsMenu(menu);
        getMenuInflater().inflate(R.menu.menu1, menu);
        return  true;
    }

    public void one(MenuItem mi)
    {
        SharedPreferences.Editor se = sp.edit();
        rl.setBackgroundColor(Color.WHITE);
        se.putInt("k1", 101);
        se.commit();
    }
    public void two(MenuItem mi)
    {
        SharedPreferences.Editor se = sp.edit();
        rl.setBackgroundColor(Color.RED);
        se.putInt("k1", 102);
        se.commit();
    }
    public void three(MenuItem mi)
    {
        SharedPreferences.Editor se = sp.edit();
        rl.setBackgroundColor(Color.GREEN);
        se.putInt("k1", 103);
        se.commit();
    }

    public void ten(View v)
    {
        Intent i = new Intent(this,Add.class);
        startActivity(i);
        overridePendingTransition(R.anim.abc_fade_in, R.anim.abc_fade_out);

    }
}


2.ADD

public class Add extends Activity {
    SQLiteDatabase db;
    EditText et1;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.add);
        et1 = (EditText)findViewById(R.id.et10);

        db = openOrCreateDatabase("StudentRecordsDB", Context.MODE_PRIVATE, null);
        db.execSQL("CREATE TABLE IF NOT EXISTS news_inf(_id integer primary key autoincrement,news_title VARCHAR);");



    }

    public void three(View v)
    {
        String n1 = et1.getText().toString().trim();


        insertData(db, n1);

        Toast.makeText(Add.this, "Added", Toast.LENGTH_SHORT).show();
        Intent main = new Intent(Add.this, MainActivity.class);
        startActivity(main);
        et1.setText("");

    }
    private void insertData(SQLiteDatabase db
            , String n1) {
        db.execSQL("insert into news_inf values(null , ? )"
                , new String[]{"  " +n1});
    }
}

3.Delete
public class Delete extends Activity {
    SQLiteDatabase db;
    TextView tv6,tv8;
    EditText e1;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.delete);
        e1 = (EditText)findViewById(R.id.textView);
        tv8 = (TextView)findViewById(R.id.textView3);

        Intent i = getIntent();
        String n6 = i.getStringExtra("k1");
        String n8 = i.getStringExtra("k3");
        e1.setText(n6);
        tv8.setText(n8);
        db = openOrCreateDatabase("StudentRecordsDB", Context.MODE_PRIVATE, null);

    }
    public  void four (View v) {

        // delete data from table

        db.execSQL("update  news_inf SET news_title='"+e1.getText()+"'WHERE _id='" + tv8.getText() + "'");
        Toast.makeText(Delete.this, "updated", Toast.LENGTH_SHORT).show();
        this.returnHome();
    }

    private void returnHome() {
        Intent home_intent = new Intent(getApplicationContext(),
                MainActivity.class).setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);

        startActivity(home_intent);
    }
}


Layouts

1.a

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:paddingBottom="@dimen/activity_vertical_margin"
    android:paddingLeft="@dimen/activity_horizontal_margin"
    android:paddingRight="@dimen/activity_horizontal_margin"
    android:id="@+id/r2"

    android:paddingTop="@dimen/activity_vertical_margin"
    tools:context="com.example.bhanu1.notepad5.MainActivity">

    <Button
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="ADD DETAILS"
        android:id="@+id/button"
        android:onClick="one"
        android:layout_marginTop="0dp"
        android:background="@drawable/file1"
        android:layout_alignParentTop="true"
        android:layout_centerHorizontal="true" />


    <ListView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:id="@+id/listView"
        android:divider="@android:color/transparent"
        android:dividerHeight="3dp"
        android:layout_alignParentRight="true"
        android:layout_alignParentEnd="true"
        android:layout_marginTop="59dp" />

    <Button
        android:layout_width="60dp"
        android:layout_height="60dp"
        android:background="@drawable/ie"
        android:layout_marginBottom="30dp"
        android:id="@+id/button2"
        android:onClick="ten"
        android:layout_alignParentBottom="true"
        android:layout_alignParentRight="true"
        android:layout_alignParentEnd="true" />


</RelativeLayout>

2.add

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="vertical" android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:gravity="center"
    android:layout_margin="20dp"
    >

    <EditText
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:id="@+id/et10"
        android:textColor="#001aff"
        android:layout_marginTop="10dp"
        android:textSize="25dp"
        android:hint="Enter text"
      />

    <Button
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="SAVE"
        android:onClick="three"
        android:layout_marginTop="20dp"
        android:textSize="25dp"
        android:id="@+id/button3"
        android:background="@drawable/file1"
        android:layout_gravity="center_horizontal" />
</LinearLayout>

3. delete

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

    <EditText
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:textAppearance="?android:attr/textAppearanceLarge"
        android:text="Large Text"
        android:layout_marginLeft="15dp"
        android:textSize="20dp"
        android:textColor="#ff0d00"
        android:id="@+id/textView" />


    <TextView
        android:layout_marginTop="10dp"
        android:textSize="20dp"
        android:layout_marginLeft="15dp"

        android:textColor="#ff0d00"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:visibility="gone"

        android:textAppearance="?android:attr/textAppearanceLarge"
        android:id="@+id/textView3" />


    <Button
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="UPDATE"
        android:layout_marginTop="25dp"
        android:id="@+id/button3"
        android:onClick="four"
        android:background="@drawable/file1"
        android:layout_gravity="center_horizontal" />

</LinearLayout>

4.line

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="vertical"
    android:background="@drawable/aa"

    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    >
    <TextView
        android:id="@+id/id1"
        android:onClick="six"
        android:layout_width="50dp"
        android:textColor="@android:color/transparent"
        android:background="@drawable/d2"
        android:layout_height="50dp"
        android:layout_gravity="right"
        android:layout_alignParentTop="true"
        android:layout_alignBottom="@+id/my_title"
        android:layout_alignParentRight="true"
        android:layout_alignParentEnd="true" />

    <TextView
        android:id="@+id/my_title"
        android:layout_width="wrap_content"
        android:layout_marginLeft="20dp"
        android:layout_height="50dp "
        android:textSize="20dp"
        />



</RelativeLayout>

Manifest file

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.example.bhanu1.notepad5">

    <application
        android:allowBackup="true"
        android:icon="@mipmap/ic_launcher"
        android:label="@string/app_name"
        android:supportsRtl="true"
        android:theme="@style/AppTheme">
        <activity android:name=".MainActivity">
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />

                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
        <activity android:name=".Add"/>
        <activity android:name=".Delete"/>

    </application>

</manifest>





Monday, 24 October 2016

Tips to reduce 5 to 10 kgs weight in one month period works

Steps to reduce weight
1.Walk in track in one kilometer dialy.
2.Eat vegeterian food without non-vegeterian food.
Follow these steps in one month you can loss weight without docter