公共静态类

时间:2017-09-21 01:05:50

标签: android

Lesson1.java

 public static class LessonListViewHolder extends RecyclerView.ViewHolder {
    String justifyTag = "<html><body style='text-align:justify;LINE-HEIGHT:20px;font-size:12px;padding-top:0px;padding-left:5px;padding-right:5px;'>%s</body></html>";
    String justifyTag1 = "<html><body style='text-align:justify;font-weight:bold;color:white;background:#2E8B57;text-align:center;LINE-HEIGHT:20px;font-size:12px;padding-top:0px;padding-left:5px;padding-right:5px;'>%s</body></html>";
    View mView;


    public LessonListViewHolder(View itemView) {
        super(itemView);

        mView = itemView;
    }

    public void setData_one(String data_one){

        //TextView post_lesson1 = (TextView) mView.findViewById(R.id.post_lesson1);
        //post_lesson1.setText(data_one);


        WebView post_lesson1 = (WebView) mView.findViewById(R.id.post_lesson1);
        String dataString = String.format(Locale.US, justifyTag1, data_one);
        post_lesson1.loadDataWithBaseURL("", dataString, "text/html", "UTF-8", "");
        post_lesson1.setWebViewClient(new Lesson1Hlink(this));

    }

Lesson1Hlink.java

public class Lesson1Hlink extends WebViewClient {

private Context context;

public Lesson1Hlink(Context context) {
    this.context = context;
}




@Override
public boolean shouldOverrideUrlLoading(WebView view, String url) {
    if(url.equals("hrupin://second_activity")){
        Intent i = new Intent(context, Simulation7.class);
        context.startActivity(i);
        return true;
    }
    return super.shouldOverrideUrlLoading(view, url);
}

}

我仍然是Android编程的新手。我似乎无法弄清楚为什么我无法在post_lesson1.setWebViewClient中调用Lesson1Hlink(新的Lesson1Hlink(this));

它说“Lesson1Hlink中的Lesson1Hlink(android.content.Context)无法应用于(com.example ........ LessonListViewHolder)”。请帮我解决这个问题。谢谢和祝福

1 个答案:

答案 0 :(得分:1)

这是因为Lesson1Hlink构造函数需要Context参数,而thisnew Lesson1Hlink(this))中的LessonListViewHolder表示为Context而不是post_lesson1.setWebViewClient(new Lesson1Hlink(mView.getContext())); 。所以你可以改成它:

Calling startActivity() from outside of an Activity  context requires the FLAG_ACTIVITY_NEW_TASK flag

也许,activity因此,请尝试将代码更改为Intent i = new Intent(context, Simulation7.class); i.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); context.startActivity(i); return true; ,如下所示:

uint32_t phaseInt(uint32_t N, enum ProcessChoice Choice) {

   uint32_t phaseInt = 0;
   uint32_t tempVar = N;

   if (tempVar == 0){
    phaseInt = 0;
   }
   if (tempVar != 0 && Choice == Even){
    while(tempVar != 0)
        {
          tempVar % 10;
           tempVar /= 10;
          if ( tempVar % 2 == 0)
          {
              doSomeAction(tempVar);
          }
        }

   }