如何做到这一点?
class DemoFragAct extends Fragment{
...
calling();
}
class demoActivity extends Activity{
...
void calling(){
...
Intent i = new Intent(getActivity(),newAct.class);
startActivity(i);
}
}
class newAct extends Activity{...}
空指针异常即将到来。
答案 0 :(得分:1)
如果我正确理解了问题,只需从您的函数启动新活动,调用父活动:
Intent intent = new Intent(getActivity(), YourNewActivity.class);
startActivity(intent);
答案 1 :(得分:1)
在基础片段中声明成员变量mContext。
function mangeText(text) {
var minCharLength = 50;
var readL ="Read Less";
var readM = "Read More";
var txt = text,
txtLength = 0,
totLength = "";
var startDisplayText = "",
startupCont = "",
hiddenContent = "";
txtLength = txt.length;
for (var i = 0; i < minCharLength; i++) {
totLength += txt[i];
//console.log("["+i+"] "+totLength);
}
if (txt.length >= (minCharLength + 50)) {
startupCont += "<span class='yughi501 _po2075 tetb_apndShw umoriRut' style='display:inline-block'> " + totLength +
" <span>" +
"<a href='#' class='txb_rdM _d1e301 _oijd51 _pedu' style='display:inline-block'> " +
readM +
"</a>" +
"</span>" +
"</span>";
hiddenContent = "<span class='yughi411 _po21075 _umori120Rut tetb_apndhd' style='display:none'> " + txt +
" <span>" +
"<a href='#' class='txb_rdL _pedu'> " +
readL +
" </a>" +
"</span>" +
"</span>";
txt = startupCont;
txt += hiddenContent;
}
return txt;
}
function ReadMoreLess(event){
//alert(event.target);
}
$(".apndbtn").click(function (){
var txt = mangeText($(".txt").val());
$(".dclr").append(txt);
$( ".txb_rdM" ).bind( "click", function() {
$(this).parents(".umoriRut").hide().next().show();
return;
});
$( ".txb_rdL" ).bind( "click", function() {
$(this).parents("._umori120Rut").hide().prev().show();
});
});
因此,您可以在任何地方使用上下文变量,而无需与持有者活动直接耦合
$( ".txb_rdM" ).bind( "click", function() {
$(this).parents(".umoriRut").hide().next().show();
return;
});
$( ".txb_rdL" ).bind( "click", function() {
$(this).parents("._umori120Rut").hide().prev().show();
});
提示您的片段必须附加到其活动,才能导航到另一个活动
答案 2 :(得分:0)
正如我之前作为评论写的那样,代码必须是这样的:
private void yourMethod(){
//your code above
Intent intent = new Intent(demoActivity.this, SecondActivity.class);
startActivity(intent);
}