여기가 내 첫 번째 질문입니다. Android 용 앱을 개발 중이며 GridView를 DataGrid로 사용하고 있습니다. 나는 7-8 열이있는 그리드가 있고 그 내용에 따라 다른 너비를 갖도록 gridview의 열을 만들어야합니다. 여기에있는 모든 게시물을 확인했지만 해결책을 찾을 수 없습니다. 지금 내가하고있는 일은 각 뷰의 LayoutParams를 고정 폭을 계산할 백분율로 설정하는 것입니다. 뷰마다 올바른 너비를 갖지만 두 번째 뷰의 텍스트가 첫 번째 뷰 위에 표시되는 식으로 진행됩니다. 내 모든보기는 TextView 또는 EditText입니다.다른 크기의 열이있는 Android GridView
나는 당신이 내게 줄 수있는 도움을 preciate 것입니다. 미리 감사드립니다.
맥시
@Override
public View getView(int position, View convertView, ViewGroup parent) {
final int row = GetRow(position);
View field = null;
String text = "";
// convertView = grid.getChildAt(position);
/*f (grid.getChildAt(position) != null) {
if (null == convertView) {
return grid.getChildAt(position);
} else {
convertView = null;
}
}*/
int width = 0;
Point size = new Point();
((Activity) context).getWindowManager().getDefaultDisplay().getSize(size);
width = weights[GetCol(position)] * (size.x - 50)/100;
if (row == 0){
text = localfieldstitles[position];
if (convertView != null){
field = (TextView) convertView;
} else {
field = new TextView(context);
}
((TextView)field).setText(text);
field.setBackgroundResource(R.drawable.buttonblue);
((TextView)field).setTextAppearance(context, android.R.style.TextAppearance_DeviceDefault_Medium);
LayoutParams params = new GridView.LayoutParams(width, LayoutParams.MATCH_PARENT);
field.setLayoutParams(params);
} else {
// Get our text for position
final int col = GetCol(position);
try {
gridData.absolute(row);
if (gridData.getString(remotefields[col]) != null) {
text = gridData.getString(remotefields[col]);
} else {
text = "";
}
if (convertView != null) {
field = convertView;
if (convertView instanceof EditText) {
((EditText) field).setText(text);
} else {
((TextView) field).setText(text);
}
} else {
if (editable[col].equalsIgnoreCase("T")) {
field = new EditText(context);
((EditText) field).setText(text);
((EditText) field).setInputType(fieldtypes[col]);
} else {
field = new TextView(context);
((TextView) field).setText(text);
}
}
if (editable[col].equalsIgnoreCase("T")) {
((EditText)field).setSingleLine();
((EditText)field).setOnEditorActionListener(
new EditText.OnEditorActionListener() {
@Override
public boolean onEditorAction(TextView v, int actionId, KeyEvent event) {
if (actionId == EditorInfo.IME_ACTION_DONE ||
actionId == EditorInfo.IME_ACTION_NEXT) {
try {
if (!isFindColumn(col)) {
gridData.absolute(row);
switch (gridData.getMetaData().getColumnType(col)) {
case Types.FLOAT:
case Types.REAL:
case Types.DECIMAL: gridData.updateFloat(localfields[col], Float.parseFloat(v.getText().toString())); break;
case Types.DOUBLE: gridData.updateDouble(localfields[col], Double.parseDouble(v.getText().toString())); break;
case Types.INTEGER: gridData.updateInt(localfields[col], Integer.parseInt(v.getText().toString())); break;
case Types.VARCHAR:
case Types.NVARCHAR:
case Types.CHAR: gridData.updateString(localfields[col], v.getText().toString()); break;
}
datachange.fieldChange(localfields[col], v.getText().toString());
} else {
findColumn.FINDTEXT = v.getText().toString();
executeSearch();
}
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
return true; // pass on to other listeners.
}
});
((EditText)field).setOnFocusChangeListener(new EditText.OnFocusChangeListener() {
public void onFocusChange(View v, boolean hasFocus) {
if(!hasFocus){
try {
if (!isFindColumn(col)) {
gridData.absolute(row);
switch (gridData.getMetaData().getColumnType(col)) {
case Types.FLOAT:
case Types.REAL:
case Types.DECIMAL: gridData.updateFloat(localfields[col], Float.parseFloat(((TextView)v).getText().toString())); break;
case Types.DOUBLE: gridData.updateDouble(localfields[col], Double.parseDouble(((TextView)v).getText().toString())); break;
case Types.INTEGER: gridData.updateInt(localfields[col], Integer.parseInt(((TextView)v).getText().toString())); break;
case Types.VARCHAR:
case Types.NVARCHAR:
case Types.CHAR: gridData.updateString(localfields[col], ((TextView)v).getText().toString()); break;
}
datachange.fieldChange(localfields[col], ((TextView)v).getText().toString());
} /*else {
findColumn.FINDTEXT = ((TextView)v).getText().toString();
executeSearch();
} */
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
//do job here owhen Edittext lose focus
}
});
}
LayoutParams params;
if (text.equalsIgnoreCase("")) {
params = new GridView.LayoutParams(width, 40);
} else {
params = new GridView.LayoutParams(width, LayoutParams.WRAP_CONTENT);
}
field.setLayoutParams(params);
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
//Finally return the view }
return field;
}
안녕하세요. 시간을 내 주셔서 대단히 감사합니다. BaseAdapter에서 상속하는 사용자 지정 어댑터가 있습니다. getView 함수에서 화면 크기 및 각 열마다 다른 고정 비율 (harcoded)으로 너비를 계산하는 뷰의 LayoutParams를 설정합니다. 어설 션에서, 그리드의 첫 번째 행 (위치 0에서 6)에있을 때 데이터 필드와 구별 할 수있는 Drawable 리소스에 대한 TextView 배경을 설정합니다. 내 질문을 업데이트하고 코드를 게시 할 예정입니다. 대단히 감사합니다 ... 감사합니다, 맥시 – Maxi