Bug fix
Missing new values in edit when they out of view SQL Query better view with IME
This commit is contained in:
parent
4fbbabbf81
commit
283af19d92
4 changed files with 62 additions and 29 deletions
app/src/main
|
@ -32,11 +32,13 @@
|
||||||
</activity>
|
</activity>
|
||||||
<activity
|
<activity
|
||||||
android:name=".ElementActivity"
|
android:name=".ElementActivity"
|
||||||
android:label="@string/title_activity_element" >
|
android:label="@string/title_activity_element"
|
||||||
|
android:windowSoftInputMode="adjustPan">
|
||||||
</activity>
|
</activity>
|
||||||
<activity
|
<activity
|
||||||
android:name=".SQLActivity"
|
android:name=".SQLActivity"
|
||||||
android:label="@string/title_activity_sql">
|
android:label="@string/title_activity_sql"
|
||||||
|
android:windowSoftInputMode="adjustResize">
|
||||||
</activity>
|
</activity>
|
||||||
</application>
|
</application>
|
||||||
|
|
||||||
|
|
|
@ -1,13 +1,14 @@
|
||||||
package info.nerull7.mysqlbrowser;
|
package info.nerull7.mysqlbrowser;
|
||||||
|
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
|
import android.view.KeyEvent;
|
||||||
import android.view.LayoutInflater;
|
import android.view.LayoutInflater;
|
||||||
import android.view.View;
|
import android.view.View;
|
||||||
import android.view.ViewGroup;
|
import android.view.ViewGroup;
|
||||||
import android.widget.ArrayAdapter;
|
import android.widget.ArrayAdapter;
|
||||||
import android.widget.EditText;
|
|
||||||
import android.widget.TextView;
|
import android.widget.TextView;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -21,33 +22,52 @@ public class ElementArrayAdapter extends ArrayAdapter<String> {
|
||||||
|
|
||||||
public ElementArrayAdapter(Context context, int resource, List<String> fields) {
|
public ElementArrayAdapter(Context context, int resource, List<String> fields) {
|
||||||
super(context, resource, fields);
|
super(context, resource, fields);
|
||||||
this.context = context;
|
init(context, resource, fields);
|
||||||
this.fields = fields;
|
values = new ArrayList<String>();
|
||||||
layout = resource;
|
for(String field: fields){
|
||||||
values = null;
|
values.add("");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public ElementArrayAdapter(Context context, int resource, List<String> fields, List<String> values) {
|
public ElementArrayAdapter(Context context, int resource, List<String> fields, List<String> values) {
|
||||||
this(context, resource, fields);
|
super(context, resource, fields);
|
||||||
this.values = values;
|
init(context, resource, fields);
|
||||||
|
this.values = new ArrayList<String>();
|
||||||
|
this.values.addAll(values); // Copy
|
||||||
|
}
|
||||||
|
|
||||||
|
private void init(Context context, int resource, List<String> fields){
|
||||||
|
this.context = context;
|
||||||
|
this.fields = fields;
|
||||||
|
layout = resource;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public View getView(int position, View convertView, ViewGroup parent) {
|
public View getView(final int position, View convertView, ViewGroup parent) {
|
||||||
LayoutInflater layoutInflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
|
LayoutInflater layoutInflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
|
||||||
View rowView = layoutInflater.inflate(layout, parent, false);
|
final View rowView = layoutInflater.inflate(layout, parent, false);
|
||||||
|
|
||||||
TextView textView = (TextView) rowView.findViewById(R.id.textFieldName);
|
TextView textView = (TextView) rowView.findViewById(R.id.textFieldName);
|
||||||
textView.setText(fields.get(position));
|
textView.setText(fields.get(position));
|
||||||
if(values != null){
|
TextView textFieldName = (TextView) rowView.findViewById(R.id.editFieldValue);
|
||||||
TextView textFieldName = (TextView) rowView.findViewById(R.id.editFieldValue);
|
textFieldName.setText(values.get(position));
|
||||||
textFieldName.setText(values.get(position));
|
textFieldName.setOnFocusChangeListener(new View.OnFocusChangeListener() {
|
||||||
}
|
@Override
|
||||||
|
public void onFocusChange(View v, boolean hasFocus) {
|
||||||
|
if (!hasFocus) {
|
||||||
|
String tmp = String.valueOf(((TextView) v).getText());
|
||||||
|
values.set(position, tmp);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
return rowView;
|
return rowView;
|
||||||
}
|
}
|
||||||
|
|
||||||
public List<String> getFieldArray(){
|
public List<String> getFieldArray(){
|
||||||
return fields;
|
return fields;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public List<String> getValues() {
|
||||||
|
return values;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -2,17 +2,22 @@ package info.nerull7.mysqlbrowser;
|
||||||
|
|
||||||
import android.app.AlertDialog;
|
import android.app.AlertDialog;
|
||||||
import android.app.Fragment;
|
import android.app.Fragment;
|
||||||
|
import android.content.Context;
|
||||||
import android.content.DialogInterface;
|
import android.content.DialogInterface;
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
|
import android.util.Log;
|
||||||
import android.view.LayoutInflater;
|
import android.view.LayoutInflater;
|
||||||
import android.view.Menu;
|
import android.view.Menu;
|
||||||
import android.view.MenuInflater;
|
import android.view.MenuInflater;
|
||||||
import android.view.MenuItem;
|
import android.view.MenuItem;
|
||||||
import android.view.View;
|
import android.view.View;
|
||||||
import android.view.ViewGroup;
|
import android.view.ViewGroup;
|
||||||
|
import android.view.inputmethod.InputMethodManager;
|
||||||
|
import android.widget.AbsListView;
|
||||||
import android.widget.EditText;
|
import android.widget.EditText;
|
||||||
import android.widget.ListView;
|
import android.widget.ListView;
|
||||||
import android.widget.ProgressBar;
|
import android.widget.ProgressBar;
|
||||||
|
import android.widget.RelativeLayout;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
@ -50,6 +55,21 @@ public class ElementFragment extends Fragment implements AsyncDatabaseConnector.
|
||||||
progressBar = (ProgressBar) rootView.findViewById(R.id.progressBar);
|
progressBar = (ProgressBar) rootView.findViewById(R.id.progressBar);
|
||||||
listView = (ListView) rootView.findViewById(R.id.listView);
|
listView = (ListView) rootView.findViewById(R.id.listView);
|
||||||
|
|
||||||
|
listView.setOnScrollListener(new AbsListView.OnScrollListener() {
|
||||||
|
@Override
|
||||||
|
public void onScrollStateChanged(AbsListView view, int scrollState) {
|
||||||
|
if(scrollState==SCROLL_STATE_TOUCH_SCROLL) {
|
||||||
|
listView.requestFocus();
|
||||||
|
InputMethodManager inputMethodManager = (InputMethodManager) getActivity().getSystemService(Context.INPUT_METHOD_SERVICE);
|
||||||
|
inputMethodManager.hideSoftInputFromWindow(listView.getWindowToken(), InputMethodManager.HIDE_NOT_ALWAYS);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onScroll(AbsListView view, int firstVisibleItem, int visibleItemCount, int totalItemCount) {
|
||||||
|
}
|
||||||
|
});
|
||||||
|
listView.setItemsCanFocus(true);
|
||||||
initArguments();
|
initArguments();
|
||||||
|
|
||||||
postExecute = POST_EXECUTE_NONE;
|
postExecute = POST_EXECUTE_NONE;
|
||||||
|
@ -64,9 +84,9 @@ public class ElementFragment extends Fragment implements AsyncDatabaseConnector.
|
||||||
List<String> fields = listAdapter.getFieldArray();
|
List<String> fields = listAdapter.getFieldArray();
|
||||||
Static.asyncDatabaseConnector.setStringReturnListener(this);
|
Static.asyncDatabaseConnector.setStringReturnListener(this);
|
||||||
if(getArguments().getBoolean(EDIT_ELEMENT))
|
if(getArguments().getBoolean(EDIT_ELEMENT))
|
||||||
Static.asyncDatabaseConnector.updateElement(tableName, fields, values, getNewValues());
|
Static.asyncDatabaseConnector.updateElement(tableName, fields, values, listAdapter.getValues());
|
||||||
else
|
else
|
||||||
Static.asyncDatabaseConnector.addNewElement(tableName, fields, getNewValues());
|
Static.asyncDatabaseConnector.addNewElement(tableName, fields, listAdapter.getValues());
|
||||||
}
|
}
|
||||||
|
|
||||||
private void actionRemove(){
|
private void actionRemove(){
|
||||||
|
@ -137,16 +157,6 @@ public class ElementFragment extends Fragment implements AsyncDatabaseConnector.
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private List<String> getNewValues(){
|
|
||||||
List<String> newValues = new ArrayList<String>();
|
|
||||||
|
|
||||||
for(int i=0; i<listView.getChildCount();i++){
|
|
||||||
EditText editText = (EditText) listView.getChildAt(i).findViewById(R.id.editFieldValue);
|
|
||||||
newValues.add(String.valueOf(editText.getText()));
|
|
||||||
}
|
|
||||||
return newValues;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onStringReturn(String data) {
|
public void onStringReturn(String data) {
|
||||||
message = data;
|
message = data;
|
||||||
|
|
|
@ -18,6 +18,7 @@
|
||||||
android:id="@+id/listView"
|
android:id="@+id/listView"
|
||||||
android:layout_below="@+id/progressBar"
|
android:layout_below="@+id/progressBar"
|
||||||
android:layout_alignParentLeft="true"
|
android:layout_alignParentLeft="true"
|
||||||
android:layout_alignParentStart="true" />
|
android:layout_alignParentStart="true"
|
||||||
|
android:descendantFocusability="afterDescendants"/>
|
||||||
|
|
||||||
</RelativeLayout>
|
</RelativeLayout>
|
Loading…
Add table
Add a link
Reference in a new issue