Commit 7779cdb5 by 石璀亮

feat(tablelayout):add common tablelayout for the table data change

1 parent 4b3e378b
......@@ -19,6 +19,16 @@
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity android:name=".SettingActivity"
android:label="@string/app_name"
>
</activity>
<activity android:name=".CommonTableActivity"
android:label="@string/app_name"
>
</activity>
</application>
</manifest>
\ No newline at end of file
package com.nbbsw.cuiliang.systemsetting;
import android.app.Activity;
import android.os.Bundle;
import android.widget.CheckBox;
import android.widget.CompoundButton;
import android.widget.TableLayout;
import android.widget.TableRow;
import android.widget.TextView;
import android.widget.Toast;
/**
* Created by st on 17-7-18.
*/
public class CommonTableActivity extends Activity {
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.common_table);
generateMemTable();
}
private void generateMemTable() {
TableLayout mytable = (TableLayout) findViewById(R.id.common_table);
int numberOfRow = 3;
int numberOfColumn = 4;
int cellDimension = 24;
int cellPadding = 2;
TableRow tableRow = new TableRow(this);
tableRow.setLayoutParams(new TableLayout.LayoutParams((cellDimension + 2 * cellPadding) * numberOfColumn, cellDimension + 2 * cellPadding));
mytable.addView(tableRow, new TableLayout.LayoutParams((cellDimension + 2 * cellPadding) * numberOfColumn, cellDimension + 2 * cellPadding));
generateTextView("口", tableRow);
generateTextView("最大运行内存", tableRow);
generateTextView("最小运行内存", tableRow);
generateTextView("状态", tableRow);
generateCommonTable(mytable, numberOfRow, numberOfColumn, cellDimension, cellPadding, tableRow);
}
private void generateCpuTable() {
TableLayout mytable = (TableLayout) findViewById(R.id.common_table);
int numberOfRow = 3;
int numberOfColumn = 6;
int cellDimension = 24;
int cellPadding = 2;
TableRow tableRow = new TableRow(this);
tableRow.setLayoutParams(new TableLayout.LayoutParams((cellDimension + 2 * cellPadding) * numberOfColumn, cellDimension + 2 * cellPadding));
mytable.addView(tableRow, new TableLayout.LayoutParams((cellDimension + 2 * cellPadding) * numberOfColumn, cellDimension + 2 * cellPadding));
generateTextView("口", tableRow);
generateTextView("类型", tableRow);
generateTextView("核数", tableRow);
generateTextView("最低频率", tableRow);
generateTextView("最高频率", tableRow);
generateTextView("状态", tableRow);
generateCommonTable(mytable, numberOfRow, numberOfColumn, cellDimension, cellPadding, tableRow);
}
private void generateCommonTable(TableLayout mytable, int numberOfRow, int numberOfColumn, int cellDimension, int cellPadding, TableRow tableRow) {
for (int row = 0; row < numberOfRow; row++) {
tableRow = new TableRow(this);
tableRow.setLayoutParams(new TableLayout.LayoutParams((cellDimension + 2 * cellPadding) * numberOfColumn, cellDimension + 2 * cellPadding));
for (int column = 0; column < numberOfColumn; column++) {
if (column < numberOfColumn - 1) {
if (column == 0){
generateTextView("口", tableRow);
}else{
generateTextView("row", tableRow);
}
}
if (column == numberOfColumn - 1) {
CheckBox checkBox = new CheckBox(this);
checkBox.setId(row);
tableRow.addView(checkBox);
checkBox.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
@Override
public void onCheckedChanged(CompoundButton buttonView,
boolean isChecked) {
if (buttonView.isChecked()) {
Toast.makeText(CommonTableActivity.this, "你点击的是第" + buttonView.getId() + "张",
Toast.LENGTH_LONG).show();
}
}
});
}
}
mytable.addView(tableRow, new TableLayout.LayoutParams((cellDimension + 2 * cellPadding) * numberOfColumn, cellDimension + 2 * cellPadding));
}
}
private void generateTextView(String s, TableRow tableRow) {
TextView textView = new TextView(this);
textView.setText(s);
tableRow.addView(textView);
}
}
package com.nbbsw.cuiliang.systemsetting;
import android.content.Context;
import android.content.Intent;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
......@@ -16,22 +18,49 @@ import java.util.List;
public class ItemAdapter extends RecyclerView.Adapter<ItemAdapter.ViewHolder> {
private List<ItemUnit> mItemUnit;
public Context context;
public ItemAdapter(List<ItemUnit> itemUnit){
public ItemAdapter(Context context, List<ItemUnit> itemUnit){
mItemUnit = itemUnit;
this.context = context;
}
@Override
public ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
View view = LayoutInflater.from(parent.getContext())
.inflate(R.layout.fruit_item, parent, false);
ViewHolder holder = new ViewHolder(view);
final ViewHolder holder = new ViewHolder(view);
// holder.itemView.setOnClickListener(new View.OnClickListener());
holder.itemView.setOnClickListener(new View.OnClickListener(){
@Override
public void onClick(View view) {
int position = holder.getAdapterPosition();
ItemUnit itemUnit = mItemUnit.get(position);
handleClickEvent(itemUnit.getName(), context);
}
});
holder.fruitImage.setOnClickListener(new View.OnClickListener(){
@Override
public void onClick(View view) {
int position = holder.getAdapterPosition();
ItemUnit itemUnit = mItemUnit.get(position);
handleClickEvent(itemUnit.getName(), context);
}
});
return holder;
}
public void handleClickEvent(String itemName, Context context){
Intent intent = new Intent(context, CommonTableActivity.class);
intent.putExtra("item", itemName);
context.startActivity(intent);
}
@Override
public void onBindViewHolder(ViewHolder holder, int position) {
ItemUnit itemUnit = mItemUnit.get(position);
......
......@@ -25,7 +25,7 @@ public class MainActivity extends AppCompatActivity {
StaggeredGridLayoutManager layoutManager = new StaggeredGridLayoutManager(3, StaggeredGridLayoutManager.VERTICAL);
recyclerView.setLayoutManager(layoutManager);
ItemAdapter adapter = new ItemAdapter(fruitList);
ItemAdapter adapter = new ItemAdapter(MainActivity.this, fruitList);
recyclerView.setAdapter(adapter);
}
......@@ -53,4 +53,5 @@ public class MainActivity extends AppCompatActivity {
}
}
\ No newline at end of file
package com.nbbsw.cuiliang.systemsetting;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
/**
* Created by st on 17-7-18.
*/
public class SettingActivity extends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.setting);
}
}
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent" >
android:layout_height="match_parent"
android:background="#ffffff"
>
<android.support.v7.widget.RecyclerView
android:id="@+id/list_view"
......
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical" android:layout_width="match_parent"
android:layout_height="match_parent">
<TableLayout
android:id="@+id/common_table"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:stretchColumns="*"
android:padding="3dip"
>
</TableLayout>
</LinearLayout>
\ No newline at end of file
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="5dp"
android:orientation="vertical">
android:orientation="vertical"
android:theme="@style/AppBaseTheme">
<ImageView
android:id="@+id/fruit_image"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
/>
android:layout_gravity="center_horizontal" />
<TextView
android:id="@+id/fruit_name"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="10dip"
android:gravity="left"
android:gravity="center"
/>
</LinearLayout>
\ No newline at end of file
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:theme="@style/AppTheme">
</LinearLayout>
\ No newline at end of file
<?xml version="1.0" encoding="utf-8"?>
<resources>
<string name="app_name">UIListViewTest</string>
<string name="action_settings">Settings</string>
<string name="app_name">系统应用</string>
<string name="action_settings">设置</string>
<string name="hello_world">Hello world!</string>
<string name="item_storage">存储</string>
<string name="item_mem">内存</string>
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!