How To Open New Activity And View The Details When We Click RecyclerView Items - android-activity

How to Open New Activity When We Click Recycler View Items And Show The Item Data In New Activity
MainActivity.java: This is My MainActivity java class
package com.codinginflow.firebaseui_firestoreexample;
import android.content.Intent;
import android.support.design.widget.FloatingActionButton;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.support.v7.widget.helper.ItemTouchHelper;
import android.view.View;
import android.widget.Toast;
import com.firebase.ui.firestore.FirestoreRecyclerOptions;
import com.google.firebase.firestore.CollectionReference;
import com.google.firebase.firestore.DocumentSnapshot;
import com.google.firebase.firestore.FirebaseFirestore;
import com.google.firebase.firestore.Query;
public class MainActivity extends AppCompatActivity {
private FirebaseFirestore db = FirebaseFirestore.getInstance();
private CollectionReference notebookRef = db.collection("Notebook");
private NoteAdapter adapter;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
FloatingActionButton buttonAddNote = findViewById(R.id.button_add_note);
buttonAddNote.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
startActivity(new Intent(MainActivity.this, NewNoteActivity.class));
}
});
setUpRecyclerView();
}
private void setUpRecyclerView() {
Query query = notebookRef.orderBy("priority", Query.Direction.DESCENDING);
FirestoreRecyclerOptions<Note> options = new FirestoreRecyclerOptions.Builder<Note>()
.setQuery(query, Note.class)
.build();
adapter = new NoteAdapter(options);
RecyclerView recyclerView = findViewById(R.id.recycler_view);
recyclerView.setHasFixedSize(true);
recyclerView.setLayoutManager(new LinearLayoutManager(this));
recyclerView.setAdapter(adapter);
new ItemTouchHelper(new ItemTouchHelper.SimpleCallback(0,
ItemTouchHelper.LEFT | ItemTouchHelper.RIGHT) {
#Override
public boolean onMove(RecyclerView recyclerView, RecyclerView.ViewHolder viewHolder, RecyclerView.ViewHolder target) {
return false;
}
#Override
public void onSwiped(RecyclerView.ViewHolder viewHolder, int direction) {
adapter.deleteItem(viewHolder.getAdapterPosition());
}
}).attachToRecyclerView(recyclerView);
adapter.setOnItemClickListener(new NoteAdapter.OnItemClickListener() {
#Override
public void onItemClick(DocumentSnapshot documentSnapshot, int position) {
Note note = documentSnapshot.toObject(Note.class);
String id = documentSnapshot.getId();
String path = documentSnapshot.getReference().getPath();
Toast.makeText(MainActivity.this,
"Position: " + position + " ID: " + id, Toast.LENGTH_SHORT).show();
}
});
}
#Override
protected void onStart() {
super.onStart();
adapter.startListening();
}
#Override
protected void onStop() {
super.onStop();
adapter.stopListening();
}
}
activity_main.xml: This Is My Activity Main Layout.xml
<?xml version="1.0" encoding="utf-8"?>
<android.support.design.widget.CoordinatorLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity">
<android.support.v7.widget.RecyclerView
android:id="#+id/recycler_view"
android:layout_width="match_parent"
android:layout_height="match_parent" />
<android.support.design.widget.FloatingActionButton
android:id="#+id/button_add_note"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="bottom|end"
android:layout_margin="16dp"
android:src="#drawable/ic_add" />
</android.support.design.widget.CoordinatorLayout>
note_item.xml
<?xml version="1.0" encoding="utf-8"?>
<android.support.v7.widget.CardView xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginEnd="8dp"
android:layout_marginStart="8dp"
android:layout_marginTop="8dp"
app:cardBackgroundColor="#FFFFE8">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:padding="8dp">
<TextView
android:id="#+id/text_view_title"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentStart="true"
android:layout_toStartOf="#id/text_view_priority"
android:ellipsize="end"
android:maxLines="1"
android:text="Title"
android:textAppearance="#style/TextAppearance.AppCompat.Large" />
<TextView
android:id="#+id/text_view_priority"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentEnd="true"
android:layout_alignParentTop="true"
android:text="1"
android:textAppearance="#style/TextAppearance.AppCompat.Large" />
<TextView
android:id="#+id/text_view_description"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentStart="true"
android:layout_below="#id/text_view_title"
android:text="Description" />
</RelativeLayout>
</android.support.v7.widget.CardView>
Note.java:
package com.codinginflow.firebaseui_firestoreexample;
public class Note {
private String title;
private String description;
private int priority;
public Note() {
//empty constructor needed
}
public Note(String title, String description, int priority) {
this.title = title;
this.description = description;
this.priority = priority;
}
public String getTitle() {
return title;
}
public String getDescription() {
return description;
}
public int getPriority() {
return priority;
}
}
NoteAdapter.java:
package com.codinginflow.firebaseui_firestoreexample;
import android.support.annotation.NonNull;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;
import com.firebase.ui.firestore.FirestoreRecyclerAdapter;
import com.firebase.ui.firestore.FirestoreRecyclerOptions;
import com.google.firebase.firestore.DocumentSnapshot;
public class NoteAdapter extends FirestoreRecyclerAdapter<Note, NoteAdapter.NoteHolder> {
private OnItemClickListener listener;
public NoteAdapter(#NonNull FirestoreRecyclerOptions<Note> options) {
super(options);
}
#Override
protected void onBindViewHolder(#NonNull NoteHolder holder, int position, #NonNull Note model) {
holder.textViewTitle.setText(model.getTitle());
holder.textViewDescription.setText(model.getDescription());
holder.textViewPriority.setText(String.valueOf(model.getPriority()));
}
#NonNull
#Override
public NoteHolder onCreateViewHolder(#NonNull ViewGroup parent, int viewType) {
View v = LayoutInflater.from(parent.getContext()).inflate(R.layout.note_item,
parent, false);
return new NoteHolder(v);
}
public void deleteItem(int position) {
getSnapshots().getSnapshot(position).getReference().delete();
}
class NoteHolder extends RecyclerView.ViewHolder {
TextView textViewTitle;
TextView textViewDescription;
TextView textViewPriority;
public NoteHolder(View itemView) {
super(itemView);
textViewTitle = itemView.findViewById(R.id.text_view_title);
textViewDescription = itemView.findViewById(R.id.text_view_description);
textViewPriority = itemView.findViewById(R.id.text_view_priority);
itemView.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
int position = getAdapterPosition();
if (position != RecyclerView.NO_POSITION && listener != null) {
listener.onItemClick(getSnapshots().getSnapshot(position), position);
}
}
});
}
}
public interface OnItemClickListener {
void onItemClick(DocumentSnapshot documentSnapshot, int position);
}
public void setOnItemClickListener(OnItemClickListener listener) {
this.listener = listener;
}
}
ActivityDetail.java: Here Is My Second Activity Detail.java And I want to Open Full Details Of An Item In This Activity
package com.codinginflow.firebaseui_firestoreexample;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
public class ActivityDeatail extends AppCompatActivity {
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_detail);
}
}
activiy_detail.xml:
<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".ActivityDetail">
<TextView
android:id="#+id/D_title"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginBottom="8dp"
android:layout_marginEnd="8dp"
android:layout_marginStart="8dp"
android:layout_marginTop="8dp"
android:text="TextView"
android:textSize="25sp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintVertical_bias="0.084" />
<TextView
android:id="#+id/D_description"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginBottom="8dp"
android:layout_marginEnd="8dp"
android:layout_marginStart="8dp"
android:layout_marginTop="8dp"
android:text="TextView"
android:textSize="25sp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="#+id/D_title"
app:layout_constraintVertical_bias="0.002" />
<TextView
android:id="#+id/D_priority"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginBottom="8dp"
android:layout_marginEnd="8dp"
android:layout_marginStart="8dp"
android:layout_marginTop="8dp"
android:text="TextView"
android:textSize="25sp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintVertical_bias="0.0" />
</android.support.constraint.ConstraintLayout>

If you want to open detailActivity bu clicking on each item of your recyclerView you can use of Intent to approach that. Something like this in your itemView.setOnClickListener
Intent intent = new Intent(view.getContext() , DetailActivity.class);
intent.putExtra("Your_key" ,
yourList.get(view.getVerticalScrollbarPosition()))
view.getContext().startActivity(intent);
And in your DetailActivity get your data like this:
YourModel model = getIntent().getSerializableExtra("Your_key");
Do not forget to Serialized your Model.

Related

JavaFX how to update label text value every time?

I am using IntellijIDEA. I have ui.fxml,Controller.java and GUI.java. Here is code:
ui.fxml
<?xml version="1.0" encoding="UTF-8"?>
<?import java.lang.*?>
<?import java.util.*?>
<?import javafx.scene.control.*?>
<?import javafx.scene.layout.*?>
<?import javafx.scene.paint.*?>
<AnchorPane id="AnchorPane" maxHeight="-Infinity" maxWidth="-Infinity" minHeight="-1.0" minWidth="-1.0" prefHeight="400.0" prefWidth="600.0" xmlns:fx="http://javafx.com/fxml/1" xmlns="http://javafx.com/javafx/2.2" fx:controller="sample.Controller">
<children>
<Button fx:id="exitBtn" cancelButton="true" layoutX="530.0" layoutY="366.0" mnemonicParsing="false" text="Exit" />
<Button fx:id="stopBtn" layoutX="460.0" layoutY="367.0" mnemonicParsing="false" text="Stop" />
<Button fx:id="startBtn" layoutX="387.0" layoutY="368.0" mnemonicParsing="false" text="Start" />
<Label fx:id="threadsLabel" layoutX="19.0" layoutY="23.0" prefWidth="45.0" text="Threads" />
<Label fx:id="threadsValue" layoutX="160.0" layoutY="26.0" prefWidth="45.0" text="0" />
<Label fx:id="smLabel" layoutX="19.0" layoutY="42.0" prefWidth="108.0" text="submit_sm sended" />
<Label fx:id="smValue" layoutX="160.0" layoutY="42.0" prefWidth="45.0" text="0" />
<Label fx:id="deliverLabel" layoutX="19.0" layoutY="61.0" prefWidth="115.0" text="deliver_sm received" />
<Label fx:id="deliverValue" layoutX="160.0" layoutY="61.0" prefWidth="45.0" text="0" />
<Label fx:id="tpsLabel" layoutX="19.0" layoutY="77.0" prefWidth="78.0" text="Current TPS" />
<Label fx:id="tpsValue" layoutX="160.0" layoutY="77.0" prefWidth="45.0" text="0" />
<Slider fx:id="speed" layoutX="213.0" layoutY="28.0" max="1000.0" min="10.0" prefWidth="317.0" showTickLabels="true" showTickMarks="false" />
</children>
</AnchorPane>
GUI.java
public class GUI extends Application {
public Logger log = Main.getLogger("log");
#Override
public void start(Stage primaryStage) throws Exception{
FXMLLoader loader = new FXMLLoader();
Parent root = loader.load(getClass().getResource("ui.fxml"));
primaryStage.setTitle("ESME Emulator");
Scene mainScene = new Scene(root, 600, 400);
primaryStage.setScene(mainScene);
primaryStage.show();
}
public void show(String[] args) {
launch(args);
}
}
Controller.java
public class Controller implements Initializable {
public Logger log=Main.getLogger("log");
#FXML
public ResourceBundle resources;
#FXML
public URL location;
#FXML
public Label deliverLabel;
#FXML
public Label deliverValue;
#FXML
public Button exitBtn;
#FXML
public Label smLabel;
#FXML
public Label smValue;
#FXML
public Slider speed;
#FXML
public Button startBtn;
#FXML
public Button stopBtn;
#FXML
public Label threadsLabel;
#FXML
public Label threadsValue;
#FXML
public Label tpsLabel;
#FXML
public Label tpsValue;
public Sample sample;
public Controller()
{
this.sample=new Sample(this);
}
public void initialize(URL location, ResourceBundle resources) {
stopBtn.setDisable(true);
startBtn.setOnAction(new EventHandler<ActionEvent>() {
public void handle(ActionEvent event) {
try {
Main.startEmulation();
startBtn.setDisable(true);
stopBtn.setDisable(false);
}catch(Exception e)
{
log.error("Exception while \"Start\" button click event: "+e.getMessage());
}
}
});
stopBtn.setOnAction(new EventHandler<ActionEvent>() {
public void handle(ActionEvent event) {
try {
Main.stopEmulation();
startBtn.setDisable(false);
stopBtn.setDisable(true);
}catch(Exception e)
{
log.error("Exception while \"Stop\" button click event: "+e.getMessage());
}
}
});
exitBtn.setOnAction(new EventHandler<ActionEvent>() {
public void handle(ActionEvent event) {
try {
Main.stopEmulation();
System.exit(0);
}catch(Exception e)
{
log.error("Exception while \"Exit\" button click event: "+e.getMessage());
}
}
});
}
}
and i have another java class which provides a while endless loop, and i need every iteration the threadsValue to be changed via thredsValue.setText("some text"), how can i do this?
p.s.excuse me for my english...
I did this, and still no result, whats wrong?
UpdateTask updTask = new UpdateTask();
Label.textProperty().bind(updTask.valueProperty());
Thread changes = new Thread(updTask);
changes.setDaemon(true);
changes.setName("UPDATE");
changes.start();
class UpdateTask extends Task<String> {
#Override
protected String call() throws Exception {
while(isRunning()) {
updateValue(Integer.toString(Main.getThreadsCount()));
}
return null;
}
}

Multiple FXML variables to 1 controller handle

How can I make a handle that applies to each of the buttons, so I don't have to make a near-identical handle for each button?
So I have a FXML file with 9 contacts, each looks like this:
<Button fx:id="id1" mnemonicParsing="false" onAction="#handleContactEmailButtonAction" prefHeight="60.0" prefWidth="380.0" style="-fx-background-color: white;">
<graphic>
<VBox style="-fx-background-color: white; -fx-border-color: white;">
<children>
<Label prefHeight="30.0" prefWidth="334.0" text="Jane Doe" />
<Label prefHeight="17.0" prefWidth="349.0" text="jdoe#britishschool.sch.ae" textAlignment="CENTER" />
</children>
</VBox>
</graphic>
</Button>
And this is the controller:
#FXML
private Button id1;
#FXML
private Button id2;
#FXML
private Button id3;
#FXML
private Button id4;
#FXML
private Button id5;
#FXML
private Button id6;
#FXML
private Button id7;
#FXML
private Button id8;
#FXML
private Button id9;
#FXML
protected void handleContactEmailButtonAction(ActionEvent event) {
try {
Desktop desktop = Desktop.getDesktop();
String message = "mailto:"+emailvariable+"?subject=Music%20Bookings";
URI uri = URI.create(message);
desktop.mail(uri);
} catch (Exception e) {
e.printStackTrace();
}
}
So if button with fx:id="id1" is clicked, then email variable changes to the email in the relevant label, and all with one controller?
Any and all help is appreciated, thank you!
Create a Map where you can get the button from event source like:
#FXML
private Button id1;
#FXML
private Button id2;
#FXML
private Button id3;
#FXML
private Button id4;
#FXML
private Button id5;
#FXML
private Button id6;
#FXML
private Button id7;
#FXML
private Button id8;
#FXML
private Button id9;
private Map<Button, String> emailVariables;
#Override
public void initialize(URL location, ResourceBundle resources)
{
emailVariables = new HashMap<Button, String>();
emailVariables.put(id1, "id1#example.com");
emailVariables.put(id2, "id2#example.com");
emailVariables.put(id3, "id3#example.com");
emailVariables.put(id4, "id4#example.com");
emailVariables.put(id5, "id5#example.com");
emailVariables.put(id6, "id6#example.com");
emailVariables.put(id7, "id7#example.com");
emailVariables.put(id8, "id8#example.com");
emailVariables.put(id9, "i91#example.com");
}
#FXML
protected void handleContactEmailButtonAction(ActionEvent event)
{
try
{
Desktop desktop = Desktop.getDesktop();
String message = "mailto:" + emailvariables.get((Button) event.getSource()) + "?subject=Music%20Bookings";
URI uri = URI.create(message);
desktop.mail(uri);
}
catch (Exception e)
{
e.printStackTrace();
}
}
Code is not tested.
Consider creating a custom component:
package application;
import java.awt.Desktop;
import java.io.IOException;
import java.net.URI;
import javafx.beans.property.SimpleStringProperty;
import javafx.beans.property.StringProperty;
import javafx.fxml.FXML;
import javafx.fxml.FXMLLoader;
import javafx.scene.control.Button;
import javafx.scene.control.Label;
public class EmailButton extends Button {
#FXML
private Label nameLabel ;
#FXML
private Label addressLabel ;
private final StringProperty name = new SimpleStringProperty();
private final StringProperty emailAddress = new SimpleStringProperty();
public EmailButton() throws IOException {
FXMLLoader loader = new FXMLLoader(getClass().getResource("emailButton.fxml"));
loader.setRoot(this);
loader.setController(this);
loader.load();
}
public void initialize() {
nameLabel.textProperty().bind(name);
addressLabel.textProperty().bind(emailAddress);
}
#FXML
private void sendEmail() {
try {
Desktop desktop = Desktop.getDesktop();
String message = "mailto:"+getEmailAddress()+"?subject=Music%20Bookings";
URI uri = URI.create(message);
desktop.mail(uri);
} catch (Exception e) {
e.printStackTrace();
}
}
public StringProperty nameProperty() {
return name ;
}
public final String getName() {
return nameProperty().get();
}
public final void setName(String name) {
nameProperty().set(name);
}
public StringProperty emailAddressProperty() {
return emailAddress ;
}
public final String getEmailAddress() {
return emailAddressProperty().get();
}
public final void setEmailAddress(String emailAddress) {
emailAddressProperty().set(emailAddress);
}
}
and emailButton.fxml:
<?xml version="1.0" encoding="UTF-8"?>
<?import javafx.scene.layout.VBox?>
<?import javafx.scene.control.Button?>
<?import javafx.scene.control.Label?>
<fx:root xmlns:fx="http://javafx.com/fxml/1" type="Button" mnemonicParsing="false" onAction="#sendEmail" prefHeight="60.0" prefWidth="380.0" style="-fx-background-color: white;">
<graphic>
<VBox style="-fx-background-color: white; -fx-border-color: white;">
<children>
<Label fx:id="nameLabel" prefHeight="30.0" prefWidth="334.0" />
<Label fx:id="addressLabel" prefHeight="17.0" prefWidth="349.0" textAlignment="CENTER" />
</children>
</VBox>
</graphic>
</fx:root>
Now in your main FXML you can just do:
<?import application.EmailButton?>
<!-- ... -->
<EmailButton name="Jane Doe" emailAddress="jdoe#britishschool.sch.ae"/>
<EmailButton name="..." emailAddress="..." />
<EmailButton name="..." emailAddress="..."/>
etc

Keyboard is hiding the EditText in Android

I have two EditText fields in Listview item layout. A new item will get added as the first row in Listview on click of a button. And I'm able to enter the text into both the fields.
Here is my code:
<ListView
android:id="#+id/items_listView"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:animationCache="false"
android:background="#color/white"
android:descendantFocusability="afterDescendants"
android:fadingEdge="none"
android:fadingEdgeLength="0dp"
android:focusable="true"
android:divider="#android:color/transparent"
android:overScrollMode="never"
android:scrollingCache="false"
android:smoothScrollbar="true" />
getView() of Adapter :
#Override
public View getView(final int position, View convertView, final ViewGroup parent) {
final ViewHolder viewHolder;
if (convertView == null || !(convertView.getTag() instanceof ViewHolder)) {
viewHolder = new ViewHolder();
convertView = inflater.inflate(R.layout.items_listview_item, null);
viewHolder.quantity = (EditText) convertView.findViewById(R.id.quantity_editText);
viewHolder.description = (EditText) convertView.findViewById(R.id.description_editText);
viewHolder.description.setInputType(InputType.TYPE_TEXT_VARIATION_VISIBLE_PASSWORD);
convertView.setTag(viewHolder);
} else {
viewHolder = (ViewHolder) convertView.getTag();
}
viewHolder.position = position;
viewHolder.description.setText(itemsArrayList.get(position).getDescription());
viewHolder.quantity.setText(itemsArrayList.get(position).getQuantity());
viewHolder.quantity.addTextChangedListener(new TextWatcher() {
#Override
public void onTextChanged(CharSequence arg0, int arg1, int arg2, int arg3) {
}
#Override
public void beforeTextChanged(CharSequence arg0, int arg1, int arg2, int arg3) {
}
#Override
public void afterTextChanged(Editable arg0) {
itemsArrayList.get(viewHolder.position).setQuantity(arg0.toString());
}
});
viewHolder.description.addTextChangedListener(new TextWatcher() {
#Override
public void onTextChanged(CharSequence arg0, int arg1, int arg2, int arg3) {
}
#Override
public void beforeTextChanged(CharSequence arg0, int arg1, int arg2, int arg3) {
}
#Override
public void afterTextChanged(Editable arg0) {
itemsArrayList.get(viewHolder.position).setDescription(arg0.toString());
}
});
return convertView;
}
private static class ViewHolder {
EditText description;
EditText quantity;
int position;
}
And I'm using adjustPan for my activity in manifest.
Here is my Issue : This is working fine on all devices that I have tested, But on Samsung Galaxy-Tab2 (10-inch Tablet), When I add a new item and tap 2nd EditText (i.e description field) the keyboard is showing just below the description field, which is fine. Now if I press any key then the keyboard is covering the description field. I cannot see what exactly is being entered into the field. 2nd EditText is completely hidden by keyboard. And this is not happening with 1st EditText field. Where I'm going wrong? Why is it not working as expected on galaxy-Tab2? Please help me. Thanks in advance.
Add this line to your Manifest :
android:windowSoftInputMode="adjustPan|adjustResize"
or you can give this line to your oncreate :
getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_VISIBLE|WindowManager.LayoutParams.SOFT_INPUT_ADJUST_RESIZE);
Try this,
android:windowSoftInputMode="adjustResize".
If this is not enough, you might need to add the property
android:fitsSystemWindows="true"
to the root layout containing your EditText.
OR
change your layout according this, Dont miss the line which is
android:isScrollContainer="true"
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/scrollview"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:isScrollContainer="true"
android:orientation="vertical">
<TableLayout
android:layout_width="fill_parent"
android:layout_height="match_parent"
android:background="#000000"
android:padding="0dp"
android:stretchColumns="*">
...
</TableLayout>
</ScrollView>

Binary XML file line #11: Error inflating class fragment

I am getting two Errors in my Code.
Caused by: java.lang.IllegalStateException: Fragment com.example.dfoley.write_to_file.topFragment did not create a view.
Caused by: android.view.InflateException: Binary XML file line #11: Error inflating class fragment both pointing to Line MainActivity.java:21 which is the following setContentView(R.layout.activity_main);
bottomFragment
package com.example.dfoley.write_to_file;
import android.app.ListFragment;
import android.os.Bundle;
import android.widget.ArrayAdapter;
import java.util.ArrayList;
public class bottomFragment extends ListFragment {
private ArrayAdapter<StateUser> adapter;
#Override
public void onActivityCreated(Bundle saveInstanceState){
ArrayList<StateUser> flight = MainContoller.getInstance().getFlights();
this.adapter = new ArrayAdapter<StateUser>(getActivity(), android.R.layout.simple_list_item_1, flight);
setListAdapter(this.adapter);
super.onActivityCreated(saveInstanceState);
}
public void refreshList(){
this.adapter.notifyDataSetChanged();
}
}
Top Fragment
package com.example.dfoley.write_to_file;
import android.app.Activity;
import android.app.Fragment;
import android.content.Context;
import android.os.Bundle;
import.android.util.Log;
import android.view.View;
import.android.widget.Button;
import android.widget.EditText;
import java.io.IOException;
import java.io.OutputStreamWriter;
public class topFragment extends Fragment{
private FlightSearcher searcher;
EditText text1;
public interface FlightSearcher {
public void refreshFlightList();
}
#Override
public void onAttach(Activity activity) {
searcher = (FlightSearcher) activity;
super.onAttach(activity);
}
#Override
public void onActivityCreated(Bundle savedInstanceState){
setupListeners();
super.onActivityCreated(savedInstanceState);
}
public void setupListeners() {
Button addUser = (Button)getActivity().findViewById(R.id.button);
addUser.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
writeToFile();
searcher.refreshFlightList();
}
});
}
private void writeToFile() {
text1=(EditText)getActivity().findViewById(R.id.editText);
String AddUsers = text1.getText().toString();
try {
OutputStreamWriter outputStreamWriter = new OutputStreamWriter(getActivity().openFileOutput("UserList", Context.MODE_PRIVATE));
outputStreamWriter.write(AddUsers);
outputStreamWriter.close();
}
catch (IOException e) {
Log.e("Exception", "File write failed: " + e.toString());
}
}
}
Main Activity
package com.example.dfoley.write_to_file;
import android.app.FragmentManager;
import android.os.Bundle;
import android.support.v4.app.FragmentActivity;
import android.view.Menu;
import android.view.MenuItem;
public class MainActivity extends FragmentActivity implements topFragment.FlightSearcher{
public void refreshFlightList() {
FragmentManager mgr = getFragmentManager();
bottomFragment bottomFragmentRef =(bottomFragment) mgr.findFragmentById(R.id.bottom_fragment);
bottomFragmentRef.refreshList();
}
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
}
#Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.menu_main, menu);
return true;
}
#Override
public boolean onOptionsItemSelected(MenuItem item) {
// Handle action bar item clicks here. The action bar will
// automatically handle clicks on the Home/Up button, so long
// as you specify a parent activity in AndroidManifest.xml.
int id = item.getItemId();
//noinspection SimplifiableIfStatement
if (id == R.id.action_settings) {
return true;
}
return super.onOptionsItemSelected(item);
}
}
activiy_main.xml
<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:paddingLeft="#dimen/activity_horizontal_margin"
android:paddingRight="#dimen/activity_horizontal_margin"
android:paddingTop="#dimen/activity_vertical_margin"
android:paddingBottom="#dimen/activity_vertical_margin"
tools:context=".MainActivity">
<fragment
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:name="com.example.dfoley.write_to_file.topFragment"
android:id="#+id/top_fragment"
android:layout_weight="1"
android:layout_alignParentTop="true"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
tools:layout="#layout/topfragment" />
<fragment
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:name="com.example.dfoley.write_to_file.bottomFragment"
android:id="#+id/bottom_fragment"
android:layout_weight="1"
android:layout_below="#+id/top_fragment"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
tools:layout="#layout/bottomfragment" />
Change fragment to FrameLayout
<FrameLayout
android:id="#+id/fragment_container"
android:layout_width="match_parent"
android:layout_height="match_parent" />
For both of your fragments, you are not telling it how to create a view. I see that you are using the tools:layout tag, but according to the Tools doc, that is only a hint to the designer; it does not actually inflate that layout:
"This attribute is typically set in a tag and is used to record which layout you want to see rendered at designtime (at runtime, this will be determined by the actions of the fragment class listed by the tag)."
Thus you need to override onCreateView, inflate your view hierarchy, and then return that:
#Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
return inflater.inflate(R.layout.topfragment, container, false);
}

In my custom Listview when i click on any row of the list the checkbox doesn't get clicked.please suggest if any?

This is my MainActivity.java
public class MainActivity extends Activity
{
ListView list;
final String[] values={"Eminem","Cold Play","Mike Shinoda","Switchfoot","Will.I.A.M"};
final String[] sub={"Rap God","Paradise","Believe","Stars","B**m"};
Integer[] imageId = {
R.drawable.eminem,
R.drawable.coldplay,
R.drawable.mike,
R.drawable.switchfoot,
R.drawable.will
};
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
MyArrayAdapter adapter = new
MyArrayAdapter(MainActivity.this,values,sub,imageId);
list=(ListView)findViewById(R.id.listView1);
list.setChoiceMode(ListView.CHOICE_MODE_MULTIPLE);
// list.setAdapter(adapter);
list.setAdapter(adapter);
list.setOnItemClickListener(new OnItemClickListener() {
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
Toast.makeText(MainActivity.this, "You Clicked at " +values[+ position], Toast.LENGTH_SHORT).show();
}
});
}
}
MyArrayAdapter.java
public class MyArrayAdapter extends ArrayAdapter<String> {
private CheckBox ch;
private final Activity context;
private final String[] web;
private final Integer[] imageId;
private String[] sub;
//private final String[] sub;
public MyArrayAdapter(Activity context, String[] web,String[] sub,Integer[] imageId)
{
super(context, R.layout.layout, web);
this.context = context;
this.web = web;
this.imageId = imageId;
this.sub=sub;
}
#Override
public View getView(int position, View view, ViewGroup parent) {
LayoutInflater inflater = context.getLayoutInflater();
View rowView= inflater.inflate(R.layout.layout, null, true);
TextView txtTitle = (TextView) rowView.findViewById(R.id.textView1);
TextView tx=(TextView)rowView.findViewById(R.id.textView2);
ch=(CheckBox) rowView.findViewById(R.id.check);
ImageView imageView = (ImageView) rowView.findViewById(R.id.imageView1);
txtTitle.setText(web[position]);
tx.setText(sub[position]);
imageView.setImageResource(imageId[position]);
return rowView;
}
}
activity_main.xml
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
<ListView
android:id="#+id/listView1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true"
android:choiceMode="singleChoice"
android:dividerHeight="0.5px"
android:divider="#318CE7" />
</RelativeLayout>
layout.xml
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
<ImageView
android:id="#+id/imageView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="#drawable/ic_launcher"
android:padding="5dp" />
<TextView
android:id="#+id/textView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true" />
<TextView
android:id="#+id/textView2"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
<CheckBox
android:id="#+id/check"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:focusable="false" />
</RelativeLayout>
Code works fine except that CheckBox gets checked as a separate view(not with the entire row) and help me on how to capture the checked data.