这是我的课程,请看下面的代码并给我建议 它是在Android下面的代码我创建适配器类我想在片段
中访问它df <- data.frame(x = 1:10 + rnorm(100),
y = 1:10 + rnorm(100))
reg <- lm(y ~ x, data = df)
star <- stargazer(reg,
style = "qje", notes.append = FALSE, notes.align = "l",
notes = "This will be replaced")
note.latex <- "\\multicolumn{5}{l} {\\parbox[t]{11cm}{ \\textit{Notes:} Logistic regression. Dependent variable: an indicator varible ... AND Some very long and interesting comment.}} \\\\"
star[grepl("Note",star)] <- note.latex
cat (star, sep = "\n")
答案 0 :(得分:0)
将上下文作为getActivity()
传递customAdapter = new Adapter(getActivity(),.......);
答案 1 :(得分:0)
如果我了解您的问题,您希望在片段中访问此适配器点击事件,您可以在其中执行某些操作。这应该是这种情况,因为适配器应该将事件传递给客户端而不是自己消费它。
要做到这一点,你需要有一个回调机制。创建一个界面
public interface IOnListItemClickListener {
void onListItemClicked();
}
适配器类中的
private IOnListItemClickListener mListItemClickListener;
public void setListItemClickListener(IOnListItemClickListener listItemClickListener) {
mListItemClickListener = listItemClickListener;
}
public View getView(int position, View convertView, ViewGroup parent) {
LayoutInflater inflater = context.getLayoutInflater();
View listViewItem = inflater.inflate(R.layout.listview_response, null, true);
TextView ResponseDate=(TextView)listViewItem.findViewById(R.id.txtdate);
TextView checkito=(TextView)listViewItem.findViewById(R.id.txtcheckintoText);
TextView message=(TextView)listViewItem.findViewById(R.id.messageText);
TextView view=(TextView)listViewItem.findViewById(R.id.documents);
view.setText("Document");
ResponseDate.setText(responsedate[position]);
checkito.setText(responsecheckinto[position]);
message.setText(responsemessage[position]);
pdf=(ImageView)view.findViewById(R.id.pdf);
pdf.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
if(null != mListItemClickListener) {
mListItemClickListener.onListItemClicked();
}
}
});
return listViewItem;
}
然后,一旦收到回叫,您就可以在片段中采取相应的操作