Hai qualcuno per favore dimmi c'è qualche possibilità di creare un DataGrid in Android, se sì significa per favore aiutami con alcuni frammenti di codice, o dare alcuni URL web correlati.Come creare un display DataGrid in Android?
8
A
risposta
9
Book.java
package com.dgrid;
public class Book {
String title;
String author;
public Book(String title, String author) {
this.title = title;
this.author = author;
}
public String getTitle() {
return title;
}
public void setTitle(String title) {
this.title = title;
}
public String getAuthor() {
return author;
}
public void setAuthor(String author) {
this.author = author;
}
}
main.xml
<?xml version="1.0" encoding="utf-8"?>
<AbsoluteLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="wrap_content"
android:layout_height="fill_parent"
>
<ListView
android:id="@+id/bookListView"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:divider="#ffffff"
/>
</AbsoluteLayout>
row.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
android:id="@+id/widget0"
android:orientation="horizontal"
android:layout_toRightOf="@android:id/icon"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="#ffffff"
xmlns:android="http://schemas.android.com/apk/res/android"
>
<com.dgrid.ListItemView
android:id="@+id/title"
android:layout_height="wrap_content"
android:layout_width="150px"
android:text="Title"
android:textSize="10sp"
android:textStyle="bold"
android:textColor="#ff000000"
/>
ListItemView.java
package com.dgrid;
import android.content.Context;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Paint;
import android.util.AttributeSet;
import android.widget.TextView;
public class ListItemView extends TextView {
private boolean isHeader = false;
private Paint linePaint;
public ListItemView(Context context, AttributeSet attrs, int defStyle) {
super(context, attrs, defStyle);
init();
}
public ListItemView(Context context, AttributeSet attrs) {
super(context, attrs);
init();
}
public ListItemView(Context context) {
super(context);
init();
}
public void init(){
linePaint = new Paint(Paint.ANTI_ALIAS_FLAG);
linePaint.setColor(Color.parseColor("#000000"));
}
public boolean isHeader() {
return isHeader;
}
public void setHeader(boolean isHeader) {
this.isHeader = isHeader;
}
@Override
protected void onDraw(Canvas canvas) {
super.onDraw(canvas);
if(isHeader){
canvas.drawColor(Color.parseColor("#AAFFFF99"));
}
canvas.drawLine(0, 0, getMeasuredWidth(), 0,linePaint);
canvas.drawLine(0, getMeasuredHeight(), getMeasuredWidth(), getMeasuredHeight(),linePaint);
canvas.drawLine(0,0, 0, getMeasuredHeight(),linePaint);
}
}
DatagridActivity.java
package com.dgrid;
import android.app.Activity;
import android.content.Context;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.ListView;
public class DatagridActivity extends Activity {
Context mContext;
Book[] books = {new Book("Title","Author"),new Book("Clean Code","Uncle Bob"),new Book("Face 2.0","Allen Cooper")};
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
mContext = this;
setContentView(R.layout.main);
ListView bookListView =(ListView)findViewById(R.id.bookListView);
LitemItemAdapter mcqListAdapter = new LitemItemAdapter(this,R.layout.row,books);
bookListView.setAdapter(mcqListAdapter);
}
class LitemItemAdapter extends ArrayAdapter<Book>{
public LitemItemAdapter(Context context, int textViewResourceId,
Book[] objects) {
super(context, textViewResourceId, objects);
}
public View getView(int position, View convertView, ViewGroup parent) {
View v = convertView;
if (v == null) {
LayoutInflater vi = (LayoutInflater) mContext.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
v = vi.inflate(R.layout.row, null);
}
Book item = books[position];
if (item != null) {
ListItemView titleView = (ListItemView) v.findViewById(R.id.title);
ListItemView authorView = (ListItemView) v.findViewById(R.id.author);
if(position == 0){
titleView.setHeader(true);
authorView.setHeader(true);
}
if(titleView != null){
titleView.setText(item.getTitle());
}
if(authorView != null){
authorView.setText(item.getAuthor());
}
}
return v;
}
}
}
+0
Non ho provato questo codice, ma penso che si possa fare a meno di widget0 per avvolgere il textview. Inoltre, il titolo è hardcoded a 150px? Cosa succede se è un titolo lungo per una riga, non assomiglierà più a un datagrid, no? –
Problemi correlati
- 1. WPF Datagrid binding and column display
- 2. Come creare Drag n Drop per celle in un DataGrid
- 3. Come creare velocemente un controllo Datagrid WPF da zero?
- 4. Display doppio schermo Android
- 5. Come creare un PopupMenu personalizzato in Android
- 6. Come creare un TextArea in Android
- 7. come creare un imageButton circolare in Android?
- 8. Come creare un Observable in Android?
- 9. come creare un selettore in Android Studio
- 10. Come creare un AttributeSet in Android?
- 11. Android: Come creare un lanciatore
- 12. @Android display/res/visualizzabile in WebView
- 13. Gestione della rotazione del display in Android
- 14. Android con display E-Ink
- 15. Come aggiornare un DataGrid WPF?
- 16. WPF DataGrid singolo clic per creare un nuovo articolo
- 17. Come posso specificare un display?
- 18. Come rilevare display esterni in Android API precedente 17
- 19. Come creare uno stile basato sullo stile DataGrid predefinito?
- 20. Collegamento a un comando in un datagrid
- 21. Display MessageBox in ASP
- 22. Come creare un BitmapImage da una matrice di pixel in pixel (display video live)
- 23. Android - Come creare un effetto shake come eliminare in iphone?
- 24. Come creare un dizionario personalizzato su Android
- 25. Come creare build.xml per un progetto Android?
- 26. Come creare un Drawable dal byte []? (Android)
- 27. Balsamiq, come inserire un pulsante in un Datagrid
- 28. Android: come creare un lettore video?
- 29. Cattura schermo di display esterno su Android?
- 30. Come creare un equalizzatore per Android
Potresti per favore approfondire cosa intendi per DataGrid? – emmby
questa è una domanda di gimme-teh-codez, prova a scrivere il codice prima dopo che hai pagato per questo, .. e poi se hai problemi, chiedi loro di farlo qui. – Reno
Ecco un componente Android DataGrid: http://www.androidjetpack.com/Home/AndroidDataGrid – user2453876