Top Menu

Drop Down MenusCSS Drop Down MenuPure CSS Dropdown Menu

Thursday, 26 November 2015

Cannot resolve symbol HttpGet,HttpClient,HttpResponce in Android Studio

Today I was facing this issue "Cannot resolve symbol DefaultHttpClient" while parsing JSON in my application.

So Friends!! if you are also facing or will face the same issue then I'm giving you the solution for it. HttpClient was deprecated in API Level 22 and removed in API Level 23, You have to use URL Conntection. If you need SDK 23, add this to your gradle:

android {
    useLibrary 'org.apache.http.legacy'
}

Please remove all jar files of Http from libs folder and add below dependencies in gradle file:

compile 'org.apache.httpcomponents:httpclient:4.5'
compile 'org.apache.httpcomponents:httpcore:4.4.3'


Read more...

Friday, 30 October 2015

Gradle Sync problem - failed to sync Gradle project

Hello guys!!

You may face this sync Gradle project when upgrade the Android Studio or low heap size like this





So here is the solution for it.

For Android Studio 1.3 : (Method 1)
Step 1 : Open gradle.properties file in your Android Studio project.
Step 2 : Add this line at the end of the file
org.gradle.jvmargs=-XX:MaxHeapSize\=256m -Xmx256m Above methods seems to work but if in case it won't then do this (Method 2)
Step 1 : Start Android studio and close any open project (File > Close Project).
Step 2 : On Welcome window, Go to Configure > Settings.
Step 3 : Go to Build, Execution, Deployment > Compiler
Step 4 : Change Build process heap size (Mbytes) to 1024 and Additional build process to VM Options to -Xmx512m.
Step 5 : Close or Restart Android Studio.
Read more...

Monday, 26 October 2015

Display HTML format text in WebView

I have faced this problem to show the HTML format text show in WebView
I found the solution for this and lets share it -

Create a xml with WebView
<LinearLayout 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"
    android:orientation="vertical"
    tools:context=".MainActivity" >

    <WebView
        android:id="@+id/webview"
        android:layout_width="match_parent"
        android:layout_height="wrap_content" />
    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="@string/hello_world" />

</LinearLayout>

Now create the Activity
package com.example.androidhtmltextsample;

import android.os.Bundle;
import android.app.Activity;
import android.webkit.WebView;

public class MainActivity extends Activity {

 WebView webView;
 
 String mimeType = "text/html";
 String encoding = "utf-8";
 String htmlText = "<ul>\n<li>Apple cider vinegar dries acne without causing any apparent discomfort.</li>" +
        "\n<li>Another interesting acne overnight treatment is the application of toothpaste.</li>" +
        "\n<li>Follow this up by applying a bit of alcohol over the affected area just prior to bedtime.</li>" +
        "\n<li>Do not apply gel based toothpastes on the affected areas.</li>\n</ul>";
 
 @Override
 protected void onCreate(Bundle savedInstanceState) {
  super.onCreate(savedInstanceState);
  setContentView(R.layout.activity_main);
  
  webView = (WebView)findViewById(R.id.webview);
  webView.loadData(htmlText, mimeType, encoding);
 }

}




Now add the Internet Permission in Menifest file
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"    
package="com.example.androidhtmltextsample"    
android:versionCode="1"    
android:versionName="1.0" >

    <uses-sdk android:minSdkVersion="8"        
              android:targetSdkVersion="23" />

    <uses-permission android:name="android.permission.INTERNET"/>
    <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>

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

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

</manifest>

Read more...

Thursday, 15 October 2015

Can we use strikethrough on sticky notes

The "Sticky Notes" that come with Windows7 happens to be a very good application. With this you can keep a track of your task list by scribbling stuff on it.

Well, since the font formating capabilities of these notes was not very impressive I was just wondering if there is an alternative to strikethrough/strikeout a scribbled line from the note... and guess what! It does have a shortcut... Just like Ctrl+b is for Bold and Ctrl+i is for itallic, Ctrl+t is for Strikethrough/Strikeout.
Read more...

Thursday, 8 October 2015

Android Button: Place Image and text in center

Hello Guys!!

If you are facing issue to place image and text at center of any button then please refer my blog -


<?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="wrap_content"
    android:orientation="vertical">



<LinearLayout
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:orientation="horizontal">
            <TableLayout
                android:layout_width="match_parent"
                android:layout_height="match_parent">
                <TableRow
                    android:layout_width="0dp"
                    android:layout_height="match_parent"
                    android:weightSum="4">
                    <RelativeLayout
                        android:id="@+id/layout_Views"
                        android:layout_width="0dp"
                        android:layout_height="match_parent"
                        android:layout_margin="2dp"
                        android:layout_weight="1"
                        android:background="@color/blue">
                        <TextView
                            android:id="@+id/txt_viewCount"
                            android:layout_width="match_parent"
                            android:layout_height="wrap_content"
                            android:layout_centerInParent="true"
                            android:gravity="center"
                            android:padding="9dp"
                            android:text="214 Views"
                            android:textColor="#fff" />
                    </RelativeLayout>
                    <RelativeLayout
                        android:id="@+id/layout_Votes"
                        android:layout_width="0dp"
                        android:layout_height="match_parent"
                        android:layout_margin="2dp"
                        android:layout_weight="1"
                        android:background="@color/red">
                        <TextView
                            android:id="@+id/txt_Votes"
                            android:layout_width="match_parent"
                            android:layout_height="wrap_content"
                            android:layout_centerInParent="true"
                            android:gravity="center"
                            android:padding="9dp"
                            android:text="214 Views"
                            android:textColor="#fff" />
                    </RelativeLayout>
                    <RelativeLayout
                        android:id="@+id/layout_share"
                        android:layout_width="0dp"
                        android:layout_height="match_parent"
                        android:layout_margin="2dp"
                        android:layout_weight="1"
                        android:background="@color/green">
                        <ImageView
                            android:id="@+id/img_share"
                            android:layout_width="wrap_content"
                            android:layout_height="wrap_content"
                            android:layout_centerInParent="true"
                            android:src="@drawable/ic_share" />
                    </RelativeLayout>
                    <RelativeLayout
                        android:id="@+id/layout_bookmark"
                        android:layout_width="0dp"
                        android:layout_height="match_parent"
                        android:layout_margin="2dp"
                        android:layout_weight="1"
                        android:background="@color/yellow">
                        <ImageView
                            android:id="@+id/img_boomark"
                            android:layout_width="wrap_content"
                            android:layout_height="wrap_content"
                            android:layout_centerInParent="true"
                            android:src="@drawable/ic_bookmark" />
                    </RelativeLayout>
                </TableRow>
            </TableLayout>
        </LinearLayout>

</LinearLayout>


Output is -

Read more...

Wednesday, 30 September 2015

How to write multi-line in EditText view

Hey guys,

I have facing problem while creating an EditText view which support multi-lines as on some application it required on creating some Form which need it.

So here I am giving you the sample code to solve this problem and save your time.

By default all the EditText widgets in Android are multi-lined.
<EditText
    android:inputType="textMultiLine" <!-- Multiline input -->
    android:lines="8" <!-- Total Lines prior display -->
    android:minLines="6" <!-- Minimum lines -->
    android:gravity="top|left" <!-- Cursor Position -->
    android:maxLines="10" <!-- Maximum Lines -->
    android:layout_height="wrap_content" <!-- Height determined by content -->
    android:layout_width="fill_parent" <!-- Fill entire width -->
    android:scrollbars="vertical" <!-- Vertical Scroll Bar -->
/>

Read more...

Create Custom Spinner with background shape

Hello Guys,

If you are looking for creating Custom Spinner like this
enter image description here

Then I am here to help you :-)
Create an XML in drawable folder with any name for example spinner_bg.xml and add the following lines
<?xml version="1.0" encoding="utf-8"?><selector xmlns:android="http://schemas.android.com/apk/res/android">
    <item>
        <layer-list>
            <item>
                <shape>
                    <stroke android:width="3dp" android:color="#ebebeb" />

                    <corners android:radius="5dp" />

                    <solid android:color="#fff"></solid>
                </shape>
            </item>
            <item>
                <bitmap android:gravity="bottom|right" android:src="@drawable/ic_arrow_drop_down" />
            </item>
        </layer-list>
    </item>
</selector>
Add the following lines to your styles.xml which is inside values folder
<style name="spinner_style" >
    <item name="android:background">@drawable/spinner</item>
    <item name="android:popupBackground">#DFFFFFFF</item>
</style>
Now add this style to your spinner as

<Spinner
    android:id="@+id/condition"
    style="@style/spinner_style"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_marginLeft="16dp"
    android:layout_marginRight="16dp"
    android:layout_marginTop="15dp"
    android:popupBackground="#cccccc" />




Read more...