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

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.

Related

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

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.

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;
}
}

Unable to show Xamarin Forms MVVM binding result in listview

I am trying to implement MVVM approach in my xamarin forms application. During the implementations, I have hit a road block. I am unable to populate the list view with the data that i recieve from the server. I am unable to identify the binding issue.
Please let me know where is my mistake? What am I missing?
View Code
<?xml version="1.0" encoding="utf-8" ?>
<ContentPage xmlns="http://xamarin.com/schemas/2014/forms"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
x:Class="Test.Views.SubtaskPage"
Title="Select Subtask"
xmlns:viewModels="clr-namespace:Test.ViewModels; assembly=Test">
<ContentPage.BindingContext>
<viewModels:SubtaskPageViewModel/>
</ContentPage.BindingContext>
<ContentPage.ToolbarItems>
<ToolbarItem x:Name="tbiAddSubtask" Text="Add Subtask" Clicked="tbiAddSubtask_Clicked"/>
</ContentPage.ToolbarItems>
<StackLayout Orientation="Vertical" Padding="10">
<ListView x:Name="lstSubtasks" ItemSelected="lstSubtasks_ItemSelected" IsPullToRefreshEnabled="True" RefreshCommand="{Binding RefreshCommand}" IsRefreshing="{Binding IsBusy}" ItemsSource="{Binding SubtaskList}}">
<ListView.ItemTemplate>
<DataTemplate>
<ViewCell>
<ViewCell.ContextActions>
<MenuItem x:Name="menuAddTimeSpent" Clicked="menuItem_Clicked" CommandParameter="{Binding Ticket}" Text="Menu" />
</ViewCell.ContextActions>
<StackLayout Padding="20,0,0,0" HorizontalOptions="StartAndExpand" Orientation="Horizontal">
<Label Text="{Binding Subject}" VerticalTextAlignment="Center" />
</StackLayout>
</ViewCell>
</DataTemplate>
</ListView.ItemTemplate>
</ListView>
</StackLayout>
</ContentPage>
Response Class Code
public class SubtasksResponse
{
public int Status { get; set; }
public string Message { get; set; }
public List<Ticket> Subtasks { get; set; }
}
View Model Code
public class SubtaskPageViewModel : INotifyPropertyChanged
{
private SubtasksResponse _subtaskList;
public SubtasksResponse SubtaskList
{
get { return _subtaskList; }
set
{
_subtaskList = value;
OnPropertyChanged(nameof(SubtaskList));
}
}
private Command _refreshCommand;
public Command RefreshCommand
{
get
{
return _refreshCommand;
}
}
bool _isBusy;
public bool IsBusy
{
get { return _isBusy; }
set
{
_isBusy = value;
OnPropertyChanged(nameof(IsBusy));
}
}
public SubtaskPageViewModel()
{
_refreshCommand = new Command(RefreshList);
}
async void RefreshList()
{
SubtaskList = await PopulateSubtaskList();
}
async Task<SubtasksResponse> PopulateSubtaskList()
{
RestService rs = new RestService();
IsBusy = true;
IsBusy = false;
var subtaskList = new SubtasksResponse();
subtaskList = await rs.GetSubtasksAsync(Convert.ToInt32(Application.Current.Properties["UserId"]));
return subtaskList;
}
public event PropertyChangedEventHandler PropertyChanged;
protected virtual void OnPropertyChanged(string propertyName)
{
if (PropertyChanged != null)
{
PropertyChanged(this, new PropertyChangedEventArgs(propertyName));
}
}
}
For starters we see you are binding the ListView to ItemsSource="{Binding SubtaskList} - when we then look at the ViewModel it seems that SubtaskList is of type SubtasksResponse, that type only has 3 properties.
But the item template inside your ListView is not using any of those 3 properties... it's using Ticket and Subject.
Are this properties of the class Subtasks? If so you need to bind the ListView directly to the List property for it to pick up the items in that collection.

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);
}