Little fun with TableLayout....
This commit is contained in:
parent
f117941a2a
commit
fb550c183e
2 changed files with 96 additions and 4 deletions
|
@ -1,19 +1,96 @@
|
|||
package info.nerull7.mysqlbrowser;
|
||||
|
||||
import android.app.ActionBar;
|
||||
import android.app.Fragment;
|
||||
import android.graphics.Canvas;
|
||||
import android.graphics.Color;
|
||||
import android.graphics.Typeface;
|
||||
import android.os.Bundle;
|
||||
import android.util.Log;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
import android.widget.RelativeLayout;
|
||||
import android.widget.TableLayout;
|
||||
import android.widget.TableRow;
|
||||
import android.widget.TextView;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* Created by nerull7 on 15.07.14.
|
||||
*/
|
||||
public class EntriesFragment extends Fragment {
|
||||
String databaseName;
|
||||
String tableName;
|
||||
TableLayout entriesTable;
|
||||
// TableLayout headerTable;
|
||||
RelativeLayout uselessParent;
|
||||
|
||||
@Override
|
||||
public View onCreateView(LayoutInflater inflater, ViewGroup container,
|
||||
Bundle savedInstanceState) {
|
||||
View rootView = inflater.inflate(R.layout.fragment_entries, container, false);
|
||||
databaseName = getArguments().getString("DatabaseName");
|
||||
tableName = getArguments().getString("TableName");
|
||||
entriesTable = (TableLayout) rootView.findViewById(R.id.entriesTable);
|
||||
// headerTable = (TableLayout) rootView.findViewById(R.id.headerTable);
|
||||
uselessParent = (RelativeLayout) rootView.findViewById(R.id.uselessParent);
|
||||
setupTable();
|
||||
return rootView;
|
||||
}
|
||||
|
||||
private void setupTable(){
|
||||
List<String> fieldList = Static.databaseConnector.getFields(tableName);
|
||||
|
||||
TableRow.LayoutParams layoutParams = new TableRow.LayoutParams(TableRow.LayoutParams.WRAP_CONTENT, TableRow.LayoutParams.WRAP_CONTENT);
|
||||
|
||||
// First we need header
|
||||
final TableRow headerRow = new TableRow(getActivity());
|
||||
headerRow.setLayoutParams(new TableRow.LayoutParams(TableRow.LayoutParams.MATCH_PARENT, TableRow.LayoutParams.WRAP_CONTENT));
|
||||
for(int i =0;i<fieldList.size();i++){
|
||||
TextView textView = new TextView(getActivity());
|
||||
textView.setText(fieldList.get(i));
|
||||
textView.setTypeface(null, Typeface.BOLD);
|
||||
textView.setLayoutParams(layoutParams);
|
||||
headerRow.addView(textView);
|
||||
}
|
||||
// headerTable.addView(headerRow);
|
||||
entriesTable.addView(headerRow);
|
||||
|
||||
View fakeHeaderView = new View(getActivity()){
|
||||
@Override
|
||||
public void draw(Canvas canvas) {
|
||||
headerRow.draw(canvas);
|
||||
// super.draw(canvas);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
|
||||
int width = headerRow.getMeasuredWidth();
|
||||
int height = headerRow.getMeasuredHeight();
|
||||
|
||||
widthMeasureSpec = MeasureSpec.makeMeasureSpec(width, MeasureSpec.EXACTLY);
|
||||
heightMeasureSpec = MeasureSpec.makeMeasureSpec(height, MeasureSpec.EXACTLY);
|
||||
|
||||
super.onMeasure(widthMeasureSpec, heightMeasureSpec);
|
||||
}
|
||||
};
|
||||
fakeHeaderView.setBackgroundColor(getResources().getColor(android.R.color.background_light));
|
||||
uselessParent.addView(fakeHeaderView);
|
||||
|
||||
// Now we get Rows
|
||||
List<List<String>> rows = Static.databaseConnector.getRows(20); //TODO some normal number definition in header
|
||||
for(int i=0;i<20;i++){ // The same arbitrary number FIXME
|
||||
List<String> elements = rows.get(i);
|
||||
TableRow newRow = new TableRow(getActivity());
|
||||
for(int j=0;j<elements.size();j++) { // elements.size is the same as in header so maybe some one number ?
|
||||
TextView textView = new TextView(getActivity());
|
||||
textView.setText(elements.get(j));
|
||||
textView.setLayoutParams(layoutParams);
|
||||
newRow.addView(textView);
|
||||
}
|
||||
entriesTable.addView(newRow);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -6,11 +6,26 @@
|
|||
android:paddingRight="@dimen/activity_horizontal_margin"
|
||||
android:paddingTop="@dimen/activity_vertical_margin"
|
||||
android:paddingBottom="@dimen/activity_vertical_margin"
|
||||
tools:context="info.nerull7.mysqlbrowser.EntriesFragment">
|
||||
tools:context="info.nerull7.mysqlbrowser.EntriesFragment"
|
||||
android:id="@+id/uselessParent">
|
||||
|
||||
<TextView
|
||||
android:text="@string/hello_world"
|
||||
<!--<TableLayout-->
|
||||
<!--android:layout_width="fill_parent"-->
|
||||
<!--android:layout_height="wrap_content"-->
|
||||
<!--android:id="@+id/headerTable"-->
|
||||
<!--android:layout_alignParentStart="true"-->
|
||||
<!--android:layout_alignParentEnd="true"></TableLayout>-->
|
||||
|
||||
<ScrollView
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content" />
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_alignParentStart="true"
|
||||
android:layout_alignParentEnd="true">
|
||||
<TableLayout
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:id="@+id/entriesTable">
|
||||
</TableLayout>
|
||||
</ScrollView>
|
||||
|
||||
</RelativeLayout>
|
||||
|
|
Loading…
Reference in a new issue