Fabian W.
- Forum-Beiträge: 17
17.05.2012, 16:36:44 via Website
17.05.2012 16:36:44 via Website
Hallo,
ich arbeite zur Zeit an einer App mit Nachrichtenfunktion.
Diese soll Ähnlichkeit mit dem Design von Whats App, Facebook haben...
Hierfür habe ich für 2 verschiedene xml Datein als Hintergrund der TextViews, die sich in Farbe, ... unterscheinden
Ich hol mir die Daten (Name, Nachricht, Datum, Lesebestätigung) per JSONParser und möchte Sie dann in den "Sprechbalsen" ausgaben.
Versucht habe ich das ganze mit einem eigenen Custom BaseAdapter.
Tutorium: http://thinkandroid.wordpress.com/2010/01/13/custom-baseadapters/
Habe diesen für mich angepasst, jedoch bewirkt er nichts.
Ich bin hier langsam am Verzweifeln -- Fabian
ich arbeite zur Zeit an einer App mit Nachrichtenfunktion.
Diese soll Ähnlichkeit mit dem Design von Whats App, Facebook haben...
Hierfür habe ich für 2 verschiedene xml Datein als Hintergrund der TextViews, die sich in Farbe, ... unterscheinden
1<shape android:shape="rectangle" xmlns:android="http://schemas.android.com/apk/res/android" >
2
3<stroke
4 android:width="2dp"
5 android:color="#C0C0C0" />
6
7<corners android:radius="5dp" />
8
9<solid android:color="#FFFF00" />
10
11<padding android:left="100dp" />
12
13<size android:width="200dp" />
14
15
16<gradient
17 android:type="linear"
18 android:angle="270"
19 android:centerColor="#32CD32"
20 android:endColor="#00FF00"
21 android:startColor="#32CD32" />
22
23</shape>
2
3<stroke
4 android:width="2dp"
5 android:color="#C0C0C0" />
6
7<corners android:radius="5dp" />
8
9<solid android:color="#FFFF00" />
10
11<padding android:left="100dp" />
12
13<size android:width="200dp" />
14
15
16<gradient
17 android:type="linear"
18 android:angle="270"
19 android:centerColor="#32CD32"
20 android:endColor="#00FF00"
21 android:startColor="#32CD32" />
22
23</shape>
Ich hol mir die Daten (Name, Nachricht, Datum, Lesebestätigung) per JSONParser und möchte Sie dann in den "Sprechbalsen" ausgaben.
Versucht habe ich das ganze mit einem eigenen Custom BaseAdapter.
Tutorium: http://thinkandroid.wordpress.com/2010/01/13/custom-baseadapters/
1class NachrichtListCursorAdapter extends BaseAdapter
2 {
3 private Context mContext;
4
5 /**
6 * Hold onto a copy of the entire Contact List.
7 */
8 private List<NachrichtEntry> mItem = new ArrayList<NachrichtEntry>();
9
10
11 public NachrichtListCursorAdapter(Context context, ArrayList<NachrichtEntry> items) {
12 mContext = context;
13 mItem = items;
14 }
15
16 public int getCount() {
17 // TODO Auto-generated method stub
18 return mItem.size();
19 }
20
21 public Object getItem(int position) {
22 // TODO Auto-generated method stub
23 return mItem.get(position);
24 }
25
26 public long getItemId(int position) {
27 // TODO Auto-generated method stub
28 return position;
29 }
30
31 public View getView(int position, View convertView, ViewGroup parent) {
32 // TODO Auto-generated method stub
33 NachrichtEntryView btv;
34 if (convertView == null) {
35 btv = new NachrichtEntryView(mContext, mItem.get(position));
36 } else {
37 btv = (NachrichtEntryView) convertView;
38 String nachricht = mItem.get(position).getNachricht();
39 btv.setNachrichtText(nachricht);
40 //String name = mItem.get(position).getName();
41 //btv.setNameText(name);
42 //int background = mItem.get(position).getBackground();
43 //btv.setBackgroundResource(background);
44 }
45 return btv;
46 }
47 }
48
49
50public class NachrichtEntryView extends LinearLayout {
51
52//private TextView mName;
53private TextView mNachricht = (TextView)findViewById(R.id.text1);
54private TextView mName = (TextView)findViewById(R.id.text1);
55
56
57public NachrichtEntryView(Context context, NachrichtEntry message) {
58 super(context);
59 this.setOrientation(VERTICAL);
60 mNachricht = new TextView(context);
61 //mName = new TextView(context);
62
63 String nachricht = message.getNachricht();
64 mNachricht.setText(nachricht);
65 mNachricht.setTextSize(19);
66 mNachricht.setTextColor(Color.BLACK);
67 mNachricht.setTypeface(Typeface.SANS_SERIF);
68
69 /*
70 String name = message.getName();
71 mName.setText(name);
72 mName.setTextSize(19);
73 mName.setTextColor(Color.BLACK);
74 mName.setTypeface(Typeface.SANS_SERIF);
75 */
76
77 //int background = message.getBackground();
78 //mNachricht.setBackgroundResource(background);
79
80 addView(mNachricht, new LinearLayout.LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT));
81 //addView(mName, new LinearLayout.LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT));
82
83
84}
85
86 public String getNameText() {
87 return mName.getText().toString();
88 }
89
90 public String getNachrichtText() {
91 return mNachricht.getText().toString();
92 }
93
94
95 public void setNameText(String name) {
96 mName.setText(name);
97 }
98
99 public void setNachrichtText(String nachricht) {
100 mNachricht.setText(nachricht);
101 }
102
103
104}
105
106
107public class NachrichtEntry {
108
109 private String mName;
110
111 private String mNachricht;
112
113 private int mBackground;
114
115 public NachrichtEntry(String name, String nachricht, int background) {
116 mName = name;
117 mNachricht = nachricht;
118 mBackground = background;
119 }
120
121 public String getName() {
122 return mName;
123 }
124
125 public String getNachricht() {
126 return mNachricht;
127 }
128
129 public int getBackground() {
130 return mBackground;
131 }
132
133 public void setName(String name) {
134 mName = name;
135 }
136
137 public void setNumber(String nachricht) {
138 mNachricht = nachricht;
139 }
140
141 public void setBackground(int background) {
142 mBackground = background;
143 }
144
145}
2 {
3 private Context mContext;
4
5 /**
6 * Hold onto a copy of the entire Contact List.
7 */
8 private List<NachrichtEntry> mItem = new ArrayList<NachrichtEntry>();
9
10
11 public NachrichtListCursorAdapter(Context context, ArrayList<NachrichtEntry> items) {
12 mContext = context;
13 mItem = items;
14 }
15
16 public int getCount() {
17 // TODO Auto-generated method stub
18 return mItem.size();
19 }
20
21 public Object getItem(int position) {
22 // TODO Auto-generated method stub
23 return mItem.get(position);
24 }
25
26 public long getItemId(int position) {
27 // TODO Auto-generated method stub
28 return position;
29 }
30
31 public View getView(int position, View convertView, ViewGroup parent) {
32 // TODO Auto-generated method stub
33 NachrichtEntryView btv;
34 if (convertView == null) {
35 btv = new NachrichtEntryView(mContext, mItem.get(position));
36 } else {
37 btv = (NachrichtEntryView) convertView;
38 String nachricht = mItem.get(position).getNachricht();
39 btv.setNachrichtText(nachricht);
40 //String name = mItem.get(position).getName();
41 //btv.setNameText(name);
42 //int background = mItem.get(position).getBackground();
43 //btv.setBackgroundResource(background);
44 }
45 return btv;
46 }
47 }
48
49
50public class NachrichtEntryView extends LinearLayout {
51
52//private TextView mName;
53private TextView mNachricht = (TextView)findViewById(R.id.text1);
54private TextView mName = (TextView)findViewById(R.id.text1);
55
56
57public NachrichtEntryView(Context context, NachrichtEntry message) {
58 super(context);
59 this.setOrientation(VERTICAL);
60 mNachricht = new TextView(context);
61 //mName = new TextView(context);
62
63 String nachricht = message.getNachricht();
64 mNachricht.setText(nachricht);
65 mNachricht.setTextSize(19);
66 mNachricht.setTextColor(Color.BLACK);
67 mNachricht.setTypeface(Typeface.SANS_SERIF);
68
69 /*
70 String name = message.getName();
71 mName.setText(name);
72 mName.setTextSize(19);
73 mName.setTextColor(Color.BLACK);
74 mName.setTypeface(Typeface.SANS_SERIF);
75 */
76
77 //int background = message.getBackground();
78 //mNachricht.setBackgroundResource(background);
79
80 addView(mNachricht, new LinearLayout.LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT));
81 //addView(mName, new LinearLayout.LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT));
82
83
84}
85
86 public String getNameText() {
87 return mName.getText().toString();
88 }
89
90 public String getNachrichtText() {
91 return mNachricht.getText().toString();
92 }
93
94
95 public void setNameText(String name) {
96 mName.setText(name);
97 }
98
99 public void setNachrichtText(String nachricht) {
100 mNachricht.setText(nachricht);
101 }
102
103
104}
105
106
107public class NachrichtEntry {
108
109 private String mName;
110
111 private String mNachricht;
112
113 private int mBackground;
114
115 public NachrichtEntry(String name, String nachricht, int background) {
116 mName = name;
117 mNachricht = nachricht;
118 mBackground = background;
119 }
120
121 public String getName() {
122 return mName;
123 }
124
125 public String getNachricht() {
126 return mNachricht;
127 }
128
129 public int getBackground() {
130 return mBackground;
131 }
132
133 public void setName(String name) {
134 mName = name;
135 }
136
137 public void setNumber(String nachricht) {
138 mNachricht = nachricht;
139 }
140
141 public void setBackground(int background) {
142 mBackground = background;
143 }
144
145}
Habe diesen für mich angepasst, jedoch bewirkt er nichts.
Ich bin hier langsam am Verzweifeln -- Fabian
— geändert am 17.05.2012, 17:10:00
Empfohlener redaktioneller Inhalt
Mit Deiner Zustimmung wird hier ein externer Inhalt geladen.
Mit Klick auf den oben stehenden Button erklärst Du Dich damit einverstanden, dass Dir externe Inhalte angezeigt werden dürfen. Dabei können personenbezogene Daten an Drittanbieter übermittelt werden. Mehr Infos dazu findest Du in unserer Datenschutzerklärung.