我有一个具体问题。我正在创建一个应用程序,允许我显示某些菜肴的接收。我设计了一个包含TextView和RatingBar的自定义适配器。所以在我的其他Activity(ViewDatabase)中,我从JSON-File(方法被称为:showData)中检索dish-name,并将其显示在获取自定义适配器的ListView上。
我现在的问题是,我不知道为什么我只能选择我的菜名(所以我的适配器的textview)或者评级栏(也在我的适配器中)。
我试图输入方法:myListView.setItemsCanFocus(true);但仍然无法工作。
我没有在适配器中为我的文本实现clicklistener吗?我试图实现一个。我需要一个明确的意图,交换活动,但我不能 从一个Adapterclass转到intent中的另一个类。
在ViewDatabse-类是onItem单击我的方法,如果我点击文本,我将更改激活。
这是我的代码:
A)
public UserInformationAdapter(Context context, List<UserInformation> objects) {
super(context, R.layout.rating_item, objects);
this.context = context;
table = objects;
}
@Override
public View getView(int position, View convertView, ViewGroup parent) {
View v = convertView;
if (v == null) {
LayoutInflater inflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
v = inflater.inflate(R.layout.rating_item, null);
}
TextView name = (TextView) v.findViewById(R.id.hauptgerichte);
RatingBar ratingBar = (RatingBar) v.findViewById(R.id.rate_bar);
UserInformation userInformation = table.get(position);
ratingBar.setOnRatingBarChangeListener(onRatingChangedListener(position));
ratingBar.setTag(position);
ratingBar.setRating(getItem(position).getRatingStar());
name.setText(userInformation.getName());
name.setTag(position);
return v;
}
private RatingBar.OnRatingBarChangeListener onRatingChangedListener(final int position) {
return new RatingBar.OnRatingBarChangeListener() {
@Override
public void onRatingChanged(RatingBar ratingBar, float v, boolean b) {
UserInformation item = getItem(position);
assert item != null;
item.setRatingStar(v);
Log.i("Adapter", "star: " + v);
}
};
}
}
这是项目(名称和评级栏):
公共类UserInformation {
private String name;
private float ratingStar;
public UserInformation(){
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
void setRatingStar(float ratingStar) {
this.ratingStar = ratingStar;
}
float getRatingStar() {
return 0;
}
@Override
public String toString(){
return name;
}
}
这是检索名称的活动:
公共类ViewDatabase扩展了AppCompatActivity {
private static final String TAG = "ViewDatabase";
private FirebaseDatabase mFirebaseDatabase;
private FirebaseAuth mAuth;
private FirebaseAuth.AuthStateListener mAuthListener;
private DatabaseReference myRef;
private String userID;
private ArrayList<String> array;
private final List<UserInformation> arr = new ArrayList<>();
private UserInformationAdapter adapter2;
private ListView mListView;
@Override
protected void onCreate(@Nullable Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.view_database_layout);
array = new ArrayList<>();
mListView = (ListView) findViewById(R.id.list_karnivoure);
mListView.setItemsCanFocus(true);
mAuth = FirebaseAuth.getInstance();
mFirebaseDatabase = FirebaseDatabase.getInstance();
myRef = mFirebaseDatabase.getReference();
FirebaseUser user = mAuth.getCurrentUser();
userID = user.getUid();
myRef.child("shakes").addValueEventListener(new ValueEventListener() {
@Override
public void onDataChange(DataSnapshot dataSnapshot) {
// This method is called once with the initial value and again
// whenever data at this location is updated.
showData(dataSnapshot);
}
@Override
public void onCancelled(DatabaseError databaseError) {
}
});
}
private void showData(DataSnapshot dataSnapshot) {
Iterable<DataSnapshot> children = dataSnapshot.getChildren();
for (DataSnapshot child: children){
UserInformation uInfo = child.getValue(UserInformation.class);
arr.add(uInfo);
adapter2 = new UserInformationAdapter(ViewDatabase.this, arr);
mListView.setAdapter(adapter2);
mListView.setItemsCanFocus(true);
mListView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
mListView.setItemsCanFocus(true);
Object listItem = mListView.getItemAtPosition(position);
Intent i = new Intent(ViewDatabase.this,KarnivoureInput.class);
i.putExtra("name", listItem.toString());
startActivity(i);
}
});
}
答案 0 :(得分:0)
https://stackoverflow.com/a/8955441/5608931
尝试将此归因添加到$message = new AMQPMessage($data);
$headers = new Wire\AMQPTable(array(
'x-foo'=>'bar',
'table'=>array('figuf', 'ghf'=>5, 5=>675),
'num1' => -4294967295,
'num2' => 5,
'num3' => -2147483648,
'true' => true,
'false' => false,
'void' => null,
'date' => new DateTime(),
'array' => array(null, 'foo', 'bar', 5, 5674625, 'ttt', array(5, 8, 2)),
'arr_with_tbl' => array(
'bar',
5,
array('foo', 57, 'ee', array('foo'=>'bar', 'baz'=>'boo', 'arr'=>array(1,2,3, true, new DateTime()))),
67,
array(
'foo'=>'bar',
5=>7,
8=>'boo',
'baz'=>3
)
),
'64bitint' => 9223372036854775807,
'64bit_uint' => '18446744073709600000',
'64bitint_neg' => -pow(2, 40)
));
$headers->set('shortshort', -5, Wire\AMQPTable::T_INT_SHORTSHORT);
$headers->set('short', -1024, Wire\AMQPTable::T_INT_SHORT);
$message->set('application_headers', $headers);
和TextView
。它可以点击但不会得到专注
RatingBar