How to get all checked items in a listView in Android?

Azhar
Updated on 07-Jul-2020 13:45:41

2K+ Views

This example demonstrates how do I get all checked items in a listView in android.Step 1 − Create a new project in Android Studio, go to File ⇒ New Project and fill all required details to create a new project.Step 2 − Add the following code to res/layout/activity_main.xml.                     Step 3 − Create a java class (CustomAdapter.java) and the following code −import android.annotation.SuppressLint; import android.content.Context; import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; import android.widget.BaseAdapter; import android.widget.CheckBox; import android.widget.TextView; import android.widget.Toast; import java.util.ArrayList; import java.util.Objects; class CustomAdapter extends BaseAdapter {    private ... Read More

How to handle the errors generated while deserializing a JSON in Java?

raja
Updated on 07-Jul-2020 13:18:11

3K+ Views

The DeserializationProblemHandler class can be registered to get called when a potentially recoverable problem is encountered during the deserialization process. We can handle the errors generated while deserializing the JSON by implementing the handleUnknownProperty() method of DeserializationProblemHandler class.Syntaxpublic boolean handleUnknownProperty(DeserializationContext ctxt, JsonParser p, JsonDeserializer deserializer, Object beanOrClass, String propertyName) throws IOExceptionExampleimport java.io.*; import com.fasterxml.jackson.core.*; import com.fasterxml.jackson.databind.*; import com.fasterxml.jackson.databind.deser.*; public class DeserializationErrorTest {    public static void main(String[] args) throws JsonMappingException, JsonGenerationException, IOException {       String jsonString = "{\"id\":\"101\", \"name\":\"Ravi Chandra\", \"address\":\"Pune\", \"salary\":\"40000\" }";       ObjectMapper objectMapper = new ObjectMapper();       DeserializationProblemHandler deserializationProblemHandler = new UnMarshallingErrorHandler();     ... Read More

How do I get the height and width of the Android Navigation Bar programmatically?

Azhar
Updated on 07-Jul-2020 13:17:19

1K+ Views

This example demonstrates how do I get the height and width of the android navigation bar programmatically.Step 1 − Create a new project in Android Studio, go to File ⇒ New Project and fill all required details to create a new project.Step 2 − Add the following code to res/layout/activity_main.xml. Step 3 − Add the following code to src/MainActivity.javaimport androidx.appcompat.app.AppCompatActivity; import android.content.res.Resources; import android.os.Bundle; import android.widget.TextView; public class MainActivity extends AppCompatActivity {    @Override    protected void onCreate(Bundle savedInstanceState) {       super.onCreate(savedInstanceState);       setContentView(R.layout.activity_main);       TextView textView = findViewById(R.id.textView);     ... Read More

How to set dialog to show with full screen in Android?

Azhar
Updated on 07-Jul-2020 13:16:44

1K+ Views

This example demonstrates how do I set the dialog to show with full screen in android.Step 1 − Create a new project in Android Studio, go to File ⇒ New Project and fill all required details to create a new project.Step 2 − Add the following code to res/layout/activity_main.xml. Step 3 − Add the following code to src/MainActivity.javaimport androidx.appcompat.app.AppCompatActivity; import android.app.Dialog; import android.os.Bundle; import android.view.View; public class MainActivity extends AppCompatActivity {    @Override    protected void onCreate(Bundle savedInstanceState) {       super.onCreate(savedInstanceState);       setContentView(R.layout.activity_main);    }    public void ClickHere(View view) {     ... Read More

How to clear an ImageView in Android?

Azhar
Updated on 07-Jul-2020 13:16:01

2K+ Views

This example demonstrates how do I clear an imageview in android.Step 1 − Create a new project in Android Studio, go to File ⇒ New Project and fill all required details to create a new project.Step 2 − Add the following code to res/layout/activity_main.xml.

How to set the absolute position of a view in Android?

Azhar
Updated on 07-Jul-2020 13:11:11

4K+ Views

This example demonstrates how do I set the absolute position of a view in android.Step 1 − Create a new project in Android Studio, go to File ⇒ New Project and fill all required details to create a new project.Step 2 − Add the following code to res/layout/activity_main.xml. Step 3 − Add the following code to src/MainActivity.javaimport androidx.appcompat.app.AppCompatActivity; import android.os.Bundle; import android.widget.ImageView; import android.widget.RelativeLayout; public class MainActivity extends AppCompatActivity {    @Override    protected void onCreate(Bundle savedInstanceState) {       super.onCreate(savedInstanceState);       setContentView(R.layout.activity_main);       RelativeLayout rl = findViewById(R.id.relativeLayout);       ImageView iv = ... Read More

How to use Font Awesome in Native Android Application?

Azhar
Updated on 07-Jul-2020 13:10:32

598 Views

This example demonstrates how do I use FontAwesome in the native android applications.Step 1 − Create a new project in Android Studio, go to File ⇒ New Project and fill all required details to create a new project.Step 2 − Add the following code to res/layout/activity_main.xml. Step 3 − Create a new download asset folder. Copy-paste the fontAwesome.ttf In the asset folder.Step 4 − Add the following code to src/MainActivity.javapackage app.com.sample; import androidx.appcompat.app.AppCompatActivity; import android.graphics.Typeface; import android.os.Bundle; import android.widget.TextView; public class MainActivity extends AppCompatActivity {    @Override    protected void onCreate(Bundle savedInstanceState) {       super.onCreate(savedInstanceState);   ... Read More

How to bring an activity to foreground i.e. top of stack in Android?

Azhar
Updated on 07-Jul-2020 13:08:06

3K+ Views

This example demonstrates how do I bring an activity to the foreground (top of stack) in android.Step 1 −Create a new project in Android Studio, go to File ⇒ New Project and fill all required details to create a new project.Step 2 − Add the following code to res/layout/activity_main.xml. Step 3 − Add the following code to src/MainActivity.javaimport androidx.appcompat.app.AppCompatActivity; import android.content.Intent; import android.os.Bundle; public class MainActivity extends AppCompatActivity {    @Override    protected void onCreate(Bundle savedInstanceState) {       super.onCreate(savedInstanceState);       setContentView(R.layout.activity_main);       Intent i = new Intent(this, MyActivity.class);       i.setFlags(Intent.FLAG_ACTIVITY_REORDER_TO_FRONT); ... Read More

How to merge two JSON strings in an order using JsonParserSequence in Java?

raja
Updated on 07-Jul-2020 13:06:13

918 Views

The JsonParserSequence is a helper class that can be used to create a parser containing two sub-parsers placed in a particular sequence. We can create a sequence using the static method createFlattened() of the JsonParserSequence class.Syntaxpublic static JsonParserSequence createFlattened(JsonParser first, JsonParser second)Exampleimport java.io.*; import com.fasterxml.jackson.core.*; import com.fasterxml.jackson.core.util.*; public class JsonParserSequenceTest {    public static void main(String[] args) throws JsonParseException, IOException {       String jsonString1 = "{\"id\":\"101\", \"name\":\"Ravi Chandra\", \"address\":\"Pune\"}";       String jsonString2 = "{\"id\":\"102\", \"name\":\"Raja Ramesh\", \"address\":\"Hyderabad\", \"contacts\":[{\"mobile\":\"9959984805\", \"home\":\"7702144400\"}]}";       JsonFactory jsonFactory = new JsonFactory();       JsonParser jsonParser1 = jsonFactory.createParser(jsonString1);       JsonParser jsonParser2 = jsonFactory.createParser(jsonString2);       ... Read More

How to check whether a headset is plugged into an Android device?

Azhar
Updated on 07-Jul-2020 13:04:53

1K+ Views

This example demonstrates how do I check whether a headset is plugged into an android device.Step 1 − Create a new project in Android Studio, go to File ⇒ New Project and fill all required details to create a new project.Step 2 − Add the following code to res/layout/activity_main.xml. Step 3 − Add the following code to src/MainActivity.javaimport androidx.appcompat.app.AppCompatActivity; import android.content.BroadcastReceiver; import android.content.Context; import android.content.Intent; import android.content.IntentFilter; import android.os.Bundle; import android.widget.Toast; public class MainActivity extends AppCompatActivity {    BroadcastReceiver broadcastReceiver;    boolean Microphone_Plugged_in = false;    @Override    protected void onCreate(Bundle savedInstanceState) {       super.onCreate(savedInstanceState);   ... Read More

Advertisements