2014-10-20 2 views
-1

У меня есть определенный дизайн в моем фотошопе, но я не могу понять, как сделать его в android для строки таблицы. Как вы можете видеть ниже на картинке, мне нужен список аварийных сигналов. Поэтому я думал сделать это как строку таблицы для каждой строки, чтобы я мог вводить материал в эту строку таблицы через * .java.Очень обычная строка списка?

Heres картина

My alarm app

и вот мой код, что я есть сейчас

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
xmlns:tools="http://schemas.android.com/tools" 
android:layout_width="match_parent" 
android:layout_height="match_parent" 
android:background="#162030" 
android:paddingBottom="@dimen/activity_vertical_margin" 
android:paddingLeft="@dimen/activity_horizontal_margin" 
android:paddingRight="@dimen/activity_horizontal_margin" 
android:paddingTop="@dimen/activity_vertical_margin" 
tools:context=".MainActivity" > 

<ScrollView 
    android:id="@+id/scrollView1" 
    android:layout_width="fill_parent" 
    android:layout_height="fill_parent" 
    android:layout_below="@+id/textView1" 
    android:layout_marginTop="76dp" 
    android:background="#131b29" 

    > 

    <TableLayout 
     android:layout_width="fill_parent" 
     android:layout_height="774dp" 
     android:orientation="vertical" > 

     <TableRow 
      android:id="@+id/TableRow04" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:layout_marginLeft="20dp" 
      android:layout_marginRight="20dp" 
      android:layout_marginTop="20dp" 
      android:layout_marginBottom="0dp" 
      android:background="#162030" 
      android:minHeight="60dp" > 
     </TableRow> 

     <TableRow 
      android:id="@+id/TableRow05" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:layout_marginLeft="20dp" 
      android:layout_marginRight="20dp" 
      android:layout_marginTop="20dp" 
      android:layout_marginBottom="0dp" 
      android:background="#162030" 
      android:minHeight="60dp" > 
     </TableRow> 

</TableLayout> 
</ScrollView> 

<TextView 
    android:id="@+id/textView1" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:layout_alignParentTop="true" 
    android:layout_centerHorizontal="true" 
    android:layout_marginTop="76dp" 
    android:shadowColor="#62f1fa" 
    android:shadowDx="0.0" 
    android:shadowDy="0.0" 
    android:shadowRadius="20" 
    android:text="0:00" 
    android:textColor="#5ee6ef" 
    android:textSize="50sp" /> 

+0

Почему бы не использовать ListView вместо TableLayout? –

+0

Да, я думал об этом на самом деле, но я havent нашел хороший пример, чтобы он выглядел так, если бы вы могли мне помочь, я был бы очень благодарен :) – Bartando

ответ

0

сделать свой основной макет XML, как это:

<RelativeLayout 
android:layout_width="match_parent" 
android:layout_height="match_parent" ... > 

<ListView 
     android:id="@+id/listview" 
     android:layout_width="match_parent" 
     android:layout_height="match_parent" > 
    </ListView> 

<TextView 
    android:id="@+id/textView1" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" ... /> 

Создание макета для пользовательского стиль элемента списка (alarm_item.xml в папке макета):

<RelativeLayout 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:orientation="vertical" > 

    <!-- This is your clock icon --> 
    <ImageView 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content"/> 

    <!-- This is your alarm clock name --> 

    <TextView 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content"/> 

    <!-- Create imageview and textview for all other needed data --> 

</RelativeLayout > 

Создать адаптер для заполнения ListView с пунктом (посмотрите there для более подробной информации):

public class AlarmAdapter extends BaseAdapter { 

    Context context; 
    Arraylist data; 
    private static LayoutInflater inflater = null; 

    public yourAdapter(Context context, Arraylist data) { 
     // TODO Auto-generated constructor stub 
     this.context = context; 
     this.data = data; 
     inflater = (LayoutInflater) context 
       .getSystemService(Context.LAYOUT_INFLATER_SERVICE); 
    } 



    @Override 
    public View getView(int position, View convertView, ViewGroup parent) { 
     // Get object from list that contains Alarm data for this view 
     // I assume that your alarm data correspond to an object name AlarmData 

     AlarmData alarmData = getItem(position) 

     View rootView = convertView; 
     if (rootView == null) 
      rootView = inflater.inflate(R.layout.alarm_item, parent, false); 

     TextView alarmClockName= (TextView) rootView.findViewById(R.id.alarm_clock_name); 
     ImageView clockIcon = (ImageView) rootView.findViewById(R.id.alarm_clock_name); 

     // Set your data there 

     clockIcon.setImageResource(iconRes); 
     alarmClockName.setText(alarmData.getName()); 

     return rootView; 
    } 
} 

Наконец получить и заполнить ListView с элементами в MainActivity:

public class AlarmActivity extends Activity { 

    // I assume that your alarm data correspond to an object name AlarmData 
    // so I define a Arraylist that will contains all alarms to display 

    ArrayList<AlarmData> alarmList = new ArrayList<Alarmdata>();  

    ListView listview; 

    /** Called when the activity is first created. */ 
    @Override 
    public void onCreate(Bundle savedInstanceState) { 
     super.onCreate(savedInstanceState); 
     setContentView(R.layout.main); 
     // Get listivew from main layout 
     listview = (ListView) findViewById(R.id.listview); 

     // Add alarm to display in alarmlist 
     alarmList.add(new AlarmData()); 
     alarmList.add(new AlarmData()); 

     // Create alarm listview adapter with current context (this) and alarmlist 
     AlarmAdapter alarmAdapter = new AlarmAdapter(this, alarmList); 

     // Set previous adapter on listview 
     listview.setAdapter(alarmAdapter); 
    } 
} 

Это лишь простой пример пользовательского адаптера списка следует, надежда это поможет вам.

После создания этого mecanisme вы просто должны работать на макете пункта

+0

Итак, мне пришлось отредактировать AlarmAdapter, чтобы сделать этот кусок работа кода, но в основном действии я не могу получить этот listview.setAdapter (новый yourAdapter (это, чтобы работать ... – Bartando

+0

Я редактирую свой ответ, чтобы добавить некоторые детали, не знаю, достаточно ли этого. Какая ошибка встречает вас с помощью setAdapter? –

+0

alarmList не может быть разрешен - это то, что им удалось получить после редактирования кода. – Bartando